New into php with some problems
am 24.07.2006 21:39:20 von ReffoHi. I used Greaeme Merrall's tutorial to make a php form.
My host did something with php, and now this script doesn't work anymore.
They said it had something to do with register_globals to do, but after I
turned
Register_Globals on, this script still doesn't work. (It worked before)
This script should make it possible to add, list, edit and delete a record
from database.
Now this script is ONLY listing the record, not deleting or anything else.
Please help!
Here's the script from Graeme Merrall:
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
if ($submit) {
// here if no ID then adding else we're editing
if ($id) {
$sql = "UPDATE employees SET
first='$first',last='$last',address='$address',position='$po sition' WHERE
id=$id";
} else {
$sql = "INSERT INTO employees (first,last,address,position) VALUES
('$first','$last','$address','$position')";
}
// run SQL against the DB
$result = mysql_query($sql);
echo "Record updated/edited!
";
} elseif ($delete) {
// delete a record
$sql = "DELETE FROM employees WHERE id=$id"; $result = mysql_query($sql);
echo "$sql Record deleted!
";
} else {
// this part happens if we don't press submit
if (!$id) {
// print the list if there is not editing
$result = mysql_query("SELECT * FROM employees",$db);
while ($myrow = mysql_fetch_array($result)) {
printf(" \n", $PHP_SELF, $myrow["id"],
$myrow["first"], $myrow["last"]);
printf("
", $PHP_SELF,
$myrow["id"]); }
}
?>
}
?>