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: