Php allows you to add, delete, modify, and query databases, and php allows you to add, delete, and delete databases.

Source: Internet
Author: User

Php allows you to add, delete, modify, and query databases, and php allows you to add, delete, and delete databases.

1. Query:

Data Display. You can embed php to output data.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

2. Deletion processing page

The deletion is linked to the deletion processing page, so you need to write a deletion processing page:

<? Php $ aaa = $ _ GET ["sno"]; // get used for deletion, as usual $ db = new mysqli ("localhost", "root", "12345678 ", "heiheihei"); // connect... $ SQL = "delete from student WHERE sno = '{$ aaa}'"; // write an SQL statement, sno primary key if ($ db-> query ($ SQL )) // execute the SQL statement {header ("location: text. php "); // go back to the table page after deletion} else {echo" failed to delete ";}?>

Laizhang:

3. Add data:

Click to enter the add page

Add page:

<Body> 

You also need a processing page to judge the addition:

<? Php $ sno = $ _ POST ["sno"]; // The $ _ POST variable is used to collect the values in the form from method = "post. $ Sname =$ _ POST ["sname"]; $ ssex =$ _ POST ["ssex"]; $ sbirthday =$ _ POST ["sbirthday"]; $ class = $ _ POST ["class"]; $ db = new mysqli ("localhost", "root", "12345678", "heiheihei "); $ SQL = "insert into student VALUES ('{$ sno}', '{$ sname}', '{$ ssex}', '{$ sbirthday }', '{$ class}') "; // Add the written data to the database if ($ db-> query ($ SQL) {header (" location: text. php "); // The header () function sends the original HTTP header to the client .} Else {echo "failed to add" ;}?>

:

4. modify data: the primary key cannot be modified !!

<Html xmlns = "http://www.w3.org/1999/xhtml"> 

]

Modification processing page:

<? Php $ sno = $ _ POST ["sno"]; $ sname = $ _ POST ["sname"]; $ ssex = $ _ POST ["ssex"]; $ sbirthday =$ _ POST ["sbirthday"]; $ class =$ _ POST ["class"]; $ db = new mysqli ("localhost", "root ", "12345678", "heiheihei"); $ SQL = "update student set sname = '{$ sname}', ssex = '{$ ssex }', sbirthday = '{$ sbirthday}', class = '{$ class}' WHERE sno = '{$ sno}' "; // check whether the sno value is passed; if ($ db-> query ($ SQL) {header ("location: text. php ") ;}else {echo" modification failed ";}?>

Modified:

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.