homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum


 11:25 pm on Aug 31, 2002 (gmt 0)

Hi all,
I'm having a bit of trouble with a piece of code here. First, the code ...

class menu {
var $menu_request = "";
var $page_link = "";
function menu() {
$this->menu_request = $_GET['type'];
$request = $this->menu_request;
if (! empty($request)) {
$sql = "select * from page_name where pname='".$request."'";
$result = dbQuery($sql);
$result = dbResult($result,0,"pname");
if ($request == $result ) {
$result = dbQuery($sql);
$result = dbResult($result,0,"page");
$this->page_link = $result;

Now the problem, I am having trouble with $_GET['type'] when I first access the page. The reason is because the url is www.mysite.com/index.php does not have the ?type= at the end of it. Now once I click on a link, it gives type a value and the error goes away. What I wanted to know is if anyone knows of a way to tell the script that if the URL string does not have a ?type=string at the end of it to not use $_GET['type']?

Now let me tell you that everytime that I put $_GET['type'] anywhere in the script, no matter if it's in a variable, if it does not have a value, it will give me the error.




 11:36 pm on Aug 31, 2002 (gmt 0)

Nevermind just fixed the problem.

I just added this code

$string = $_SERVER['QUERY_STRING'];
if (empty($string)) {
$this->menu_request = "home";
} else
$this->menu_request = $_GET['type'];

Sorry for the bother


 11:47 pm on Aug 31, 2002 (gmt 0)

And if i go to your page as: [yoursite.tld...] you will still get that error...

isset -- Determine whether a variable is set


returns true if the variable you're asking about is set.

Also, (and i'm just seeing this) it can test for several variables at once! (Looks like it's exclusive, every $var has to be set for it to return true.)


 12:19 am on Sep 1, 2002 (gmt 0)

actually slade it's working good the I've set it. But I am gonna use isset and see how it goes. Thanks :)


 6:44 am on Sep 1, 2002 (gmt 0)

Only reason I bring it up is I've seen some strange stuff tacked on to URLs... not to mention a recent post about AOL hosing up search links with &'s in them.


 9:51 pm on Sep 1, 2002 (gmt 0)

Hi Slade,
Thanks for the tip. It seems to work a lot better with the isset() function.

Here's the code I used

if (isset($_GET['type']) and $_GET['type'] != "") {
$this->menu_request = $_GET['type'];
} else {
$this->menu_request = "home";

isset($_GET['type']) checks to see if it's set, and $_GET['type'] != "" checks to see if it is empty. For example, if the ?type= has nothing for a value, it'll check that as well.

OK Slade, thanks once again.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved