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 15117 Dec 9, 2002, 3:22 AM
Post Re: [TheIceman] Undefined Variable: Error. Why??
yogi 14831 Dec 9, 2002, 3:31 AM
Thread Re: [TheIceman] Undefined Variable: Error. Why??
Andy 14905 Dec 9, 2002, 4:04 AM
Post Re: [Andy] Undefined Variable: Error. Why??
TheIceman 14850 Dec 9, 2002, 4:17 AM
Thread Re: [TheIceman] Undefined Variable: Error. Why??
hennagaijin 14862 Dec 9, 2002, 5:01 AM
Thread Re: [hennagaijin] Undefined Variable: Error. Why??
TheIceman 14871 Dec 10, 2002, 4:34 AM
Thread Re: [TheIceman] Undefined Variable: Error. Why??
hennagaijin 14869 Dec 10, 2002, 4:43 AM
Thread Re: [hennagaijin] Undefined Variable: Error. Why??
TheIceman 14763 Dec 10, 2002, 11:57 PM
Thread Re: [TheIceman] Undefined Variable: Error. Why??
Andy 14856 Dec 11, 2002, 3:07 AM
Post Re: [Andy] Undefined Variable: Error. Why??
brewt 14727 Dec 11, 2002, 3:14 AM
Thread Re: [hennagaijin] Undefined Variable: Error. Why??
brewt 14783 Dec 11, 2002, 3:18 AM
Thread Re: [brewt] Undefined Variable: Error. Why??
Andy 14803 Dec 11, 2002, 3:27 AM
Thread Re: [Andy] Undefined Variable: Error. Why??
brewt 14770 Dec 11, 2002, 3:30 AM
Thread Re: [brewt] Undefined Variable: Error. Why??
Andy 14831 Dec 11, 2002, 4:12 AM
Thread Re: [Andy] Undefined Variable: Error. Why??
Paul 14739 Dec 11, 2002, 4:19 AM
Thread Re: [Paul] Undefined Variable: Error. Why??
TheIceman 14769 Dec 11, 2002, 4:40 AM
Post Re: [TheIceman] Undefined Variable: Error. Why??
Andy 14781 Dec 11, 2002, 5:35 AM
Post Re: [brewt] Undefined Variable: Error. Why??
TheIceman 14759 Dec 11, 2002, 3:45 AM