substituting for $id with globals off (newbie)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, thanks for earlier replies regarding php resources. I am currently
hitting a brick wall on the script below due to my lack of understanding of
php coupled with my lack of knowledge about globals.
 
I replaced $id with $_GET['id'] in line 5 which now allows the user to reach
the script to evaluate when presented with testpage.php?id=n. It now falls
over when it tries to run the query part :

WHERE id=$id

I tried to submit this instance with $_GET['id'] in the query which also
fails. In the $_GET['id'] where is the value for id now stored?
Can anyone see where i have gone wrong?

thanks
---
my source:

<?PHP 
$db = mysql_connect("localhost", "root");
mysql_select_db("bsdb1",$db);
// display individual record
if ($_GET['id']) { 
$result = mysql_query("SELECT * FROM address WHERE id=$id",$db);
$myrow = mysql_fetch_array($result);
printf("Name: %s\n<br>", $myrow["name"]);
printf("Address: %s\n<br>", $myrow["address"]);
printf("Home Number: %s\n<br>", $myrow["hnum"]);
printf("Work Number: %s\n<br>", $myrow["wnum"]);

} else { 
// show employee list
$result = mysql_query("SELECT * FROM address",$db);
if ($myrow = mysql_fetch_array($result)) {
// display list if there are records to display
do { 
printf("<a href=\"%s?id=%s\">%s</a><br>\n", $_SERVER['PHP_SELF'],
$myrow["id"], $myrow["name"]);
} while ($myrow = mysql_fetch_array($result));
} else { 
// no records to display
echo "Sorry, no records were found!";
} 
} 
?> 
-- 
Mike Karthauser 
Managing Director - Brightstorm Ltd

Email       >> mikek@brightstorm.co.uk
Web         >> http://www.brightstorm.co.uk
Tel         >> 0117 9426653 (office)
               07939 252144 (mobile)

Snailmail   >> Unit 8, 14 King Square,
               Bristol BS2 8JJ


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux