php mysq data editing and updating example /* This article is an entry-level PHP tutorial. It mainly tells you how to use PHP to edit and update MySQL data.
php tutorial mysq data editing and update example
/*
This article is an entry-level PHP tutorial. It mainly tells you how to use PHP to edit and update MySQL data.
*/
$db = mysql tutorial_connect("localhost", "phpdb", "phpdb");
mysql_select_db("test",$db);//If the submit button is submitted
if ($submit) {
// If there is no id, the record is being added, otherwise the record is being modified
if ($id) {
$sql = "update employees set first='$first',last='$last', address='$address',position='$position' where id=$id";
}
else {
$sql = "insert into employees (first,last,address,position) values ('$first','$last','$address','$position')";
}
//Issue sql command to database tutorial
$result = mysql_query($sql);
echo "Record modified successfully!<>";
echo "return";
}
elseif ($delete) {
//Delete a record
$sql = "delete from employees where id=$id";
$result = mysql_query($sql);
echo "Record deleted successfully!<>";
echo "return";
}
else {
// If the submit button has not been pressed yet, then execute the following part of the program
If (!$id) {
// If the status is not modified, display the employee list
$result = mysql_query("select * from employees",$db);
While ($myrow = mysql_fetch_array($result)) {
printf("%s %s n",
$php_self, $myrow["id"], $myrow["first"], $myrow["last"]);
Printf("(delete)
", $php_self, $myrow["id"]);
}
}
?>
return
}
?>