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 19227 Dec 9, 2002, 3:22 AM
Post Re: [TheIceman] Undefined Variable: Error. Why??
yogi 18840 Dec 9, 2002, 3:31 AM
Thread Re: [TheIceman] Undefined Variable: Error. Why??
Andy 18919 Dec 9, 2002, 4:04 AM
Post Re: [Andy] Undefined Variable: Error. Why??
TheIceman 18856 Dec 9, 2002, 4:17 AM
Thread Re: [TheIceman] Undefined Variable: Error. Why??
hennagaijin 18876 Dec 9, 2002, 5:01 AM
Thread Re: [hennagaijin] Undefined Variable: Error. Why??
TheIceman 18882 Dec 10, 2002, 4:34 AM
Thread Re: [TheIceman] Undefined Variable: Error. Why??
hennagaijin 18876 Dec 10, 2002, 4:43 AM
Thread Re: [hennagaijin] Undefined Variable: Error. Why??
TheIceman 18777 Dec 10, 2002, 11:57 PM
Thread Re: [TheIceman] Undefined Variable: Error. Why??
Andy 18872 Dec 11, 2002, 3:07 AM
Post Re: [Andy] Undefined Variable: Error. Why??
brewt 18738 Dec 11, 2002, 3:14 AM
Thread Re: [hennagaijin] Undefined Variable: Error. Why??
brewt 18793 Dec 11, 2002, 3:18 AM
Thread Re: [brewt] Undefined Variable: Error. Why??
Andy 18819 Dec 11, 2002, 3:27 AM
Thread Re: [Andy] Undefined Variable: Error. Why??
brewt 18789 Dec 11, 2002, 3:30 AM
Thread Re: [brewt] Undefined Variable: Error. Why??
Andy 18844 Dec 11, 2002, 4:12 AM
Thread Re: [Andy] Undefined Variable: Error. Why??
Paul 18753 Dec 11, 2002, 4:19 AM
Thread Re: [Paul] Undefined Variable: Error. Why??
TheIceman 18780 Dec 11, 2002, 4:40 AM
Post Re: [TheIceman] Undefined Variable: Error. Why??
Andy 18797 Dec 11, 2002, 5:35 AM
Post Re: [brewt] Undefined Variable: Error. Why??
TheIceman 18762 Dec 11, 2002, 3:45 AM