Hello,
I am new to PHP. I am trying the following sample script, however, it does not work.
The problem seems to be the following : when entering :
http://localhost/three.php?id=2 , this value 2 is not passed into the script. (so, the "if" never works, "else" is always activated).
Any Ideas ?
Many Thanks
Dirk
<html>
<body>
<?php
$db = mysql_connect("localhost");
mysql_select_db("usages",$db);
// display individual record
print ($userid);
if ($userid) {
$result = mysql_query("SELECT * FROM users WHERE id=$id",$db);
$myrow = mysql_fetch_array($result);
printf("First name: %s\n<br>", $myrow["firstname"]);
printf("Last name: %s\n<br>", $myrow["lastname"]);
printf("Birthyear: %s\n<br>", $myrow["birthyear"]);
printf("Email: %s\n<br>", $myrow["email"]);
} else {
// show employee list
$result = mysql_query("SELECT * FROM users",$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["firstname"], $myrow["lastname"]);
} while ($myrow = mysql_fetch_array($result));
} else {
// no records to display
echo "Sorry, no records were found!";
}
}
?>
</body>
</html>