Following webmonkey and it doesn't work
Posted: Sun Dec 01, 2002 9:21 pm
I am really new to PHP/MySQL. I am familar with straight HTML, but have never tried connecting to a database. So I was following an example on webmonkey (http://hotwired.lycos.com/webmonkey/99/ ... rogramming) and am having problems. I think it has something to do with this global variable thing, but I cannot seem to figure out what it all is saying. There is too much techno talk. Here is the code I am trying.
A simple explaination of why "if ($id)" does not work and the correct syntax would be great. The error I am getting is:
Notice: Undefined variable
dawho
?>
Code: Select all
<?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!";
}
}
?>Notice: Undefined variable
dawho
?>