Click to See Complete Forum and Search --> : Picking up variable from URL


lisar
07-14-2003, 05:37 PM
Hi All,
I am having a major issue with an install - so close but so far away!!
OK I have installed Apache, PHP module, MySQL on a Windows 2000 and a 98 machine ( I know WINDOWS!!!) I have done this sucessfully before on another 98 machine so I can't see what the problem is.
Now when I do this in the browser
http://localhost/3q/test.php

The first example should be:
$sql2 = "SELECT id,name FROM 3q_nav";

this is fine ...


however when I do this in the browser
http://localhost/3q/test.php?id=1
and run this code
$sql2 = "SELECT id,name FROM 3q_nav WHERE id = $id";

I get an error
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in c:\program files\apache
group\apache\htdocs\3q\test_2.php on line 16


Somewhere in my config files I am disallowing the WHERE or not picking up
the $id from the URL

I have checked the http.conf files buit can't seem to see any difference.

I would really appreciate any solutions
NOTE: It is not the code because it works fine on another machine - I can't even do a simple echo from the URL

Thanks for your assistance
All the best
Lisa

stolzyboy
07-14-2003, 07:00 PM
replace this

$sql2 = "SELECT id,name FROM 3q_nav WHERE id = $id";

with this

$id = $_GET['id'];
$sql2 = "SELECT id,name FROM 3q_nav WHERE id = '$id';";

piersk
07-15-2003, 06:38 AM
Or, you could get rid of the extra line and have:

$sql2 = "SELECT id, name FROM 3q_nav WHERE id = '$_GET[id]';


Note: There are no single quote marks either side of the id in the $_GET array.

However, my way and stolzy's will do exactly the same thing.

sameerni
07-15-2003, 08:03 AM
or else if you turn register_globals on in php.ini file it should work with your code. So you don't have to use $_GET[id] every time. But before that read a security note in manuals.

It should look like this in php.ini file
***************************************
register_globals = on

***************************************
This will also allow you to use posted values without using $_POST[mypostval]

Sameer

stolzyboy
07-15-2003, 10:37 AM
Originally posted by sameerni
or else if you turn register_globals on in php.ini file it should work with your code. So you don't have to use $_GET[id] every time. But before that read a security note in manuals.

It should look like this in php.ini file
***************************************
register_globals = on

***************************************
This will also allow you to use posted values without using $_POST[mypostval]

Sameer

leave it the way it is, don't turn register_globals = On