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 15479 Dec 9, 2002, 3:22 AM
Post Re: [TheIceman] Undefined Variable: Error. Why??
yogi 15174 Dec 9, 2002, 3:31 AM
Thread Re: [TheIceman] Undefined Variable: Error. Why??
Andy 15250 Dec 9, 2002, 4:04 AM
Post Re: [Andy] Undefined Variable: Error. Why??
TheIceman 15191 Dec 9, 2002, 4:17 AM
Thread Re: [TheIceman] Undefined Variable: Error. Why??
hennagaijin 15205 Dec 9, 2002, 5:01 AM
Thread Re: [hennagaijin] Undefined Variable: Error. Why??
TheIceman 15215 Dec 10, 2002, 4:34 AM
Thread Re: [TheIceman] Undefined Variable: Error. Why??
hennagaijin 15211 Dec 10, 2002, 4:43 AM
Thread Re: [hennagaijin] Undefined Variable: Error. Why??
TheIceman 15108 Dec 10, 2002, 11:57 PM
Thread Re: [TheIceman] Undefined Variable: Error. Why??
Andy 15204 Dec 11, 2002, 3:07 AM
Post Re: [Andy] Undefined Variable: Error. Why??
brewt 15071 Dec 11, 2002, 3:14 AM
Thread Re: [hennagaijin] Undefined Variable: Error. Why??
brewt 15126 Dec 11, 2002, 3:18 AM
Thread Re: [brewt] Undefined Variable: Error. Why??
Andy 15148 Dec 11, 2002, 3:27 AM
Thread Re: [Andy] Undefined Variable: Error. Why??
brewt 15118 Dec 11, 2002, 3:30 AM
Thread Re: [brewt] Undefined Variable: Error. Why??
Andy 15176 Dec 11, 2002, 4:12 AM
Thread Re: [Andy] Undefined Variable: Error. Why??
Paul 15084 Dec 11, 2002, 4:19 AM
Thread Re: [Paul] Undefined Variable: Error. Why??
TheIceman 15113 Dec 11, 2002, 4:40 AM
Post Re: [TheIceman] Undefined Variable: Error. Why??
Andy 15127 Dec 11, 2002, 5:35 AM
Post Re: [brewt] Undefined Variable: Error. Why??
TheIceman 15099 Dec 11, 2002, 3:45 AM