I got the solution: Adding this line before if($id): $id = $_GET['id']; Similarily, may add $submit=$_POST['submit'];,$firstname=$_POST['firstname']; if handle forms, like insertion a record into database. On Mon, 24 Nov 2003, Mingyan Shao wrote: > Hi, there, > > I am learning PHP/MySQL now, and got an sample code from > http://hotwired.lycos.com/webmonkey/99/21/index3a_page3.html?tw=programming, > but when I test the code on my machine, it does not work as it > suppose to. > > What it should do is: when you first run the php code, it > gives the names of the employees, each of which creates a link to the > detail info, for example, <a href=\"%s?id=%s\">%s %s</a><br>\n", > $PHP_SELF, $myrow["id"], $myrow["last"], $myrow["position"]>. When you > click any name, it should get the query value($id) from the URL, and use > it to search in the database. > > It seems can't get the $id from the URL querystring, i.e., the html page > does not change after I click a specific name. > > > The code is the following: > > <?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!"; > > } > > } > > ?> > > > > Any comments and suggestions are appreciated. > > -Mingyan > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php