Ok, here is the situation, I am using PHP_SELF and trying to get the PHP to interpret a variable from a form. The problem is that the variable is not being read by the PHP. I've tried lots of different variables of the PHP_SELF function itself, and I don't think that that is the problem. Of course when I hit the link with the corresponding id the browser address bar reads:
http://192.168.1.1/mypage.php?id=1
But the data is not interpreted. Can someone help me out.
Here is the code:
<html>
<body>
<?php
$db = mysql_connect("192.168.1.108", "root");
mysql_select_db("mydb",$db);
if ($id) {
// query the DB
$sql = "SELECT * FROM employees WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
First name:<input type="Text" name="first" value="<?php echo $myrow["first"] ?>"><br>
Last name:<input type="Text" name="last" value="<?php echo $myrow["last"] ?>"><br>
Address:<input type="Text" name="address" value="<?php echo $myrow["address"] ?>"><br>
Position:<input type="Text" name="position" value="<?php echo $myrow["position"] ?>"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
} else {
// display list of employees
$result = mysql_query("SELECT * FROM employees",$db);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href=\"%s?id=%s\">%s %s</a><br>\n", $PHP_SELF, $myrow["id"], $myrow["first"], $myrow["last"]);
}
}
?>
</body>
</html>