This article describes how to connect PHP to the database and how to add, delete, modify, and query the database. it is helpful for you to learn php.
1. query:
Data Display. you can embed php to output data.
Untitled Document
| Code |
Name |
Gender |
Birthday |
Class |
Operation |
Query ($ SQL); // execute the SQL statement and return it to rif ($ r) // condition {while ($ attr = $ r-> fetch_row ()) {$ ssex = ""; if ($ attr [2]) {$ ssex = "male";} else {$ ssex = "female";} echo"
| {$ Attr [0]} |
{$ Attr [1]} |
{$ Ssex} |
{$ Attr [3]} |
{$ Attr [4]} | // Add a click event to prevent accidental deletion.
Delete changes |
";}}?>
Add page
2. deletion processing page
The deletion is linked to the deletion processing page, so you need to write a deletion processing page:
Query ($ SQL) // execute the SQL statement {header ("location: text. php "); // go back to the table page after deletion} else {echo" failed to delete ";}?>
Laizhang:
The add page is displayed.
Add page:
Add
You also need a processing page to judge the addition:
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 !!
Untitled DocumentModify
Query ($ SQL); $ arr = $ r-> fetch_row ();?>
Modification processing page:
Query ($ SQL) {header ("location: text. php") ;}else {echo "modification failed" ;}?>
Modified:
For more articles on addition, deletion, modification, and query of php databases, please follow the PHP Chinese website!