I'm new to PHP and I'm working thru the webmonkey PHP tutorial at:
http://hotwired.lycos.com/webmonkey/99/ ... rogramming
Its not doing what the tutorial says it will do. It only ever displays the records and doens't show the record detail.
I dont think the problem is the code, because i copied and pasted it from the web page.
Is there something about my implementation I should check out? I installed the lastest version of SWAMP.
The problem seems to be that its not seeing the POST variables.
Any suggestions? Here is the code from the tutorial:
<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>
Help with WebMonkey tutorial .... code doesn't work
Moderator: General Moderators
That code requires register_globals to be On (most out of date code does, and register_globals should be Off).
Just turning register_globals On in your php.ini file (and restarting the web server) should 'make the code work'. Ideally you'd rewrite the code so that it didn't need register_globals to be On, but if you just want it to work for now then a php.ini edit should do it.
See http://php.net/variables.predefined for more info on the effects of register_globals.
Just turning register_globals On in your php.ini file (and restarting the web server) should 'make the code work'. Ideally you'd rewrite the code so that it didn't need register_globals to be On, but if you just want it to work for now then a php.ini edit should do it.
See http://php.net/variables.predefined for more info on the effects of register_globals.