Tutorial Code is Buggy :)
Posted: Thu May 15, 2003 5:38 pm
I am receiving the following error when I run the code shown below. I am confused how this code could be producing errors since I obtained it from a Web Monkey Tutorial.
URL: http://hotwired.lycos.com/webmonkey/99/ ... rogramming
I am running PHP Version 4.3.1 on a Windows Machine
Please help I love php and would like to learn how to use it.
Thank You.
Error
---------------------------------------------------------------
Notice: Undefined variable: id in C:\Documents and Settings\Administrator\My Documents\Inetpub\wwwroot\php\p\lesson2.php on line 15
Notice: Undefined variable: PHP_SELF in C:\Documents and Settings\Administrator\My Documents\Inetpub\wwwroot\php\p\lesson2.php on line 41
Bob Smith
Notice: Undefined variable: PHP_SELF in C:\Documents and Settings\Administrator\My Documents\Inetpub\wwwroot\php\p\lesson2.php on line 41
John Roberts
Notice: Undefined variable: PHP_SELF in C:\Documents and Settings\Administrator\My Documents\Inetpub\wwwroot\php\p\lesson2.php on line 41
Brad Johnson
Notice: Undefined variable: PHP_SELF in C:\Documents and Settings\Administrator\My Documents\Inetpub\wwwroot\php\p\lesson2.php on line 41
Notice: Undefined variable: PHP_SELF in C:\Documents and Settings\Administrator\My Documents\Inetpub\wwwroot\php\p\lesson2.php on line 41
Notice: Undefined variable: PHP_SELF in C:\Documents and Settings\Administrator\My Documents\Inetpub\wwwroot\php\p\lesson2.php on line 41
---------------------------------------
code
---------------------------------------
<html>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
// display individual record
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", $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>
URL: http://hotwired.lycos.com/webmonkey/99/ ... rogramming
I am running PHP Version 4.3.1 on a Windows Machine
Please help I love php and would like to learn how to use it.
Thank You.
Error
---------------------------------------------------------------
Notice: Undefined variable: id in C:\Documents and Settings\Administrator\My Documents\Inetpub\wwwroot\php\p\lesson2.php on line 15
Notice: Undefined variable: PHP_SELF in C:\Documents and Settings\Administrator\My Documents\Inetpub\wwwroot\php\p\lesson2.php on line 41
Bob Smith
Notice: Undefined variable: PHP_SELF in C:\Documents and Settings\Administrator\My Documents\Inetpub\wwwroot\php\p\lesson2.php on line 41
John Roberts
Notice: Undefined variable: PHP_SELF in C:\Documents and Settings\Administrator\My Documents\Inetpub\wwwroot\php\p\lesson2.php on line 41
Brad Johnson
Notice: Undefined variable: PHP_SELF in C:\Documents and Settings\Administrator\My Documents\Inetpub\wwwroot\php\p\lesson2.php on line 41
Notice: Undefined variable: PHP_SELF in C:\Documents and Settings\Administrator\My Documents\Inetpub\wwwroot\php\p\lesson2.php on line 41
Notice: Undefined variable: PHP_SELF in C:\Documents and Settings\Administrator\My Documents\Inetpub\wwwroot\php\p\lesson2.php on line 41
---------------------------------------
code
---------------------------------------
<html>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
// display individual record
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", $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>