Ok I am trying to get my PHP to interpret form data from within itself, and I really don't understand the syntax for posting and getting data from within PHP, can someone show me exactly how its done with an example or help me with my code. Thanks a lot.
Here is my code:
<html>
<body>
<?php
$db = mysql_connect("192.168.1.108", "root");
mysql_select_db("mydb",$db);
if ($_GET[submit]) {
$id = $GET[id];
$first = $GET[first];
$last = $GET[last];
$address = $GET[address];
$position = $_GET[position];
$sql = "UPDATE employees SET first='$first',last='$last',address='$address',position='$position' WHERE id=$id";
echo "<center>Information updated!</center>";
}
else {
if ($_GET[id]) {
// query the DB
$id = $_GET[id];
$sql = "SELECT * FROM employees WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form method="post" action="<?php $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="Post Data">
</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>