Add, delete, modify, and query a php database

Source: Internet
Author: User
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
 
  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" 
   // Add a click event to prevent accidental deletion. 
    ";}}?> 
  
Code Name Gender Birthday Class Operation
{$ Attr [0]} {$ Attr [1]} {$ Ssex} {$ Attr [3]} {$ Attr [4]}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!

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.