Data deletion and modification

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.