Gossamer Forum
Home : General : Internet Technologies :

Undefined Variable: Error. Why??

Quote Reply
Undefined Variable: Error. Why??
Ive got a script here that gives me the error 'Undefined Variable: id' in it. I had the $PHP_SELF give errors before i replaced it with '$_SERVER['PHP_SELF']' if that helps any. Im running it off an IIS server.

Can anyone tell me how to get rid of this error and make my script work?

Code:
<html>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
if ($id) {
$result = mysql_query("SELECT * FROM employees WHERE id=$id",$db);
$myrow = mysql_fetch_array($result);
printf("First name: %s\n<br>", $myrow["first"]);
printf("Last name: %s\n<br>", $myrow["last"]);
printf("Address: %s\n<br>", $myrow["address"]);
printf("Position: %s\n<br>", $myrow["position"]);
} else {
// show employee list
$result = mysql_query("SELECT * FROM employees",$db);
if ($myrow = mysql_fetch_array($result)) {
// display list if there are records to display
do {
printf("<a href=\"%s?id=%s\">%s %s</a><br>\n", $_SERVER['PHP_SELF'], $myrow["id"], $myrow["first"], $myrow["last"]);
} while ($myrow = mysql_fetch_array($result));
} else {
// no records to display
echo "Sorry, no records were found!";
}
} ?> </body>
</html>
Subject Author Views Date
Thread Undefined Variable: Error. Why?? TheIceman 14767 Dec 9, 2002, 3:22 AM
Post Re: [TheIceman] Undefined Variable: Error. Why??
yogi 14493 Dec 9, 2002, 3:31 AM
Thread Re: [TheIceman] Undefined Variable: Error. Why??
Andy 14565 Dec 9, 2002, 4:04 AM
Post Re: [Andy] Undefined Variable: Error. Why??
TheIceman 14515 Dec 9, 2002, 4:17 AM
Thread Re: [TheIceman] Undefined Variable: Error. Why??
hennagaijin 14524 Dec 9, 2002, 5:01 AM
Thread Re: [hennagaijin] Undefined Variable: Error. Why??
TheIceman 14534 Dec 10, 2002, 4:34 AM
Thread Re: [TheIceman] Undefined Variable: Error. Why??
hennagaijin 14535 Dec 10, 2002, 4:43 AM
Thread Re: [hennagaijin] Undefined Variable: Error. Why??
TheIceman 14426 Dec 10, 2002, 11:57 PM
Thread Re: [TheIceman] Undefined Variable: Error. Why??
Andy 14518 Dec 11, 2002, 3:07 AM
Post Re: [Andy] Undefined Variable: Error. Why??
brewt 14391 Dec 11, 2002, 3:14 AM
Thread Re: [hennagaijin] Undefined Variable: Error. Why??
brewt 14447 Dec 11, 2002, 3:18 AM
Thread Re: [brewt] Undefined Variable: Error. Why??
Andy 14466 Dec 11, 2002, 3:27 AM
Thread Re: [Andy] Undefined Variable: Error. Why??
brewt 14430 Dec 11, 2002, 3:30 AM
Thread Re: [brewt] Undefined Variable: Error. Why??
Andy 14493 Dec 11, 2002, 4:12 AM
Thread Re: [Andy] Undefined Variable: Error. Why??
Paul 14403 Dec 11, 2002, 4:19 AM
Thread Re: [Paul] Undefined Variable: Error. Why??
TheIceman 14433 Dec 11, 2002, 4:40 AM
Post Re: [TheIceman] Undefined Variable: Error. Why??
Andy 14443 Dec 11, 2002, 5:35 AM
Post Re: [brewt] Undefined Variable: Error. Why??
TheIceman 14423 Dec 11, 2002, 3:45 AM