Example of adding, deleting, and modifying information from multiple people
1. Main Page
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
2. Add a page
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">Add processing code for a page
<?php$code=$_post["Code"); $name =$_post["name"]; $sex =$_post["sex"]; $s =1;if ($sex = = "female") {$s = 0;} $nation =$_post["Nation"); $birthday =$_post["Birthday"]; $db =new mysqli ("localhost", "root", "" "," MyDB "), $sql =" INSERT into Info values (' {$code} ', ' {$name} ', {$s}, ' {$nation} ', ' { $birthday} '), $result = $db->query ($sql), if ($result) {header ("location:add.php");//Jump to Add.php}else{echo "add failed! ";}
3. Modify the page
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">Modify the processing code of the page
<?php$code=$_post["Code"); $name =$_post["name"]; $sex =$_post["sex"]; $s =1;if ($sex = = "female") {$s = 0;} $nation =$_post["Nation"]; $birthday =$_post["Birthday"]; $db =new mysqli ("localhost", "root", "", "MyDB"); $sql = "Update Info set name= ' {$name} ', sex={$s},nation= ' {$nation} ', birthday= ' {$birthday} ' where code= ' {$code} '; $r = $db->query ( $sql); if ($r) {header ("location:main.php");} Else{echo "Modification failed! ";}
4. Code to delete data
<?php$code=$_get["Code"]; $db =new mysqli ("localhost", "root", "", "MyDB"); $sql = "Delete from info where code= ' {$code} $r = $db->query ($sql), if ($r) {header ("location:main.php");} Else{echo "Delete failed! ";}
Data deletion and modification