Home  >  Article  >  Backend Development  >  php mysq data editing and updating example_PHP tutorial

php mysq data editing and updating example_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:05:08800browse

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


if ($id) {
// We are in the editing and modification state, so select a record
$sql = "select * from employees where id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$first = $myrow["first"];
$last = $myrow["last"];
$address = $myrow["address"];
$position = $myrow["position"];
// Display the id for users to edit and modify
?>

}
?>
Name:
Last name:


Address:
Position:




}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630808.htmlTechArticlephp mysq data editing and update example/*This article is also an entry-level php tutorial, mainly to tell you How to use php mysq data editing and update. PHP tutorial mysq data editing and updating example...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn