Different Problem [Re: Passing a Variable to PHP Via the URL]

From: Date: Tue, 11 Jun 2002 16:16:58 +0000
Subject: Different Problem [Re: Passing a Variable to PHP Via the URL]
Groups: php.general 
Request: Send a blank email to php-general+get-101566@lists.php.net to get a copy of this message
I found out that in fact PHP is creating a variable with the name and value I'm passing through a URL from the querystring. But it's still not working as planned. The url server/test.php?id=1 creates the following results in my code: printf("Variables: %s\n<br>", $HTTP_GET_VARS["id"]); This line works - there IS a variable named 'id' in my page and it has the correct value, 1. if ($id) {} This fails. If I test 'id' instead of '$id' then it works but my page doesn't seem to equate 'id=1' with the presence of $id. $result = mysql_query("SELECT * FROM employees WHERE id=$id",$db); This doesn't work - again it seems $id isn't being treated properly. I get this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource If I hardwire my page with the line '$id=1;' before the if statement and the query everything works. So why isn't the variable from my URL being treated properly? Jesse

« previous php.general (#101566) next »