PHP connects to the database to add, delete, modify, and query operations on the registration page. php addition and deletion _ PHP Tutorial

Source: Internet
Author: User
PHP connects to the database to add, delete, modify, and query the registration page, and adds and deletes php. PHP connects to the database to add, delete, modify, and query operations on the registration page. The php addition, deletion, and examples in this article share with you how to add, delete, modify, and query operations on the registration page by connecting to the database in PHP, for your reference, you can use PHP to connect to the database to add, delete, modify, and query the registration page.

The examples in this article share with you how to add, delete, modify, and query the PHP registration page by connecting to the database for your reference. The details are as follows:

1. connect to the database

<? Php // local test $ host = '000000. 0.0.1 '; $ port = 3306; $ user = "root"; $ pwd = ""; $ link = @ mysql_connect ("{$ host }:{ $ port }", $ user, $ pwd, true); if (! $ Link) {die ("Connect Server Failed :". mysql_error ();} // select the name of the connected Database mysql_select_db ("my"); // set the character encoding utf8 mysql_set_charset ('utf8');?>

2. Registration page (html page)

 
  DocumentRegistration page

3. display registration data in the database

// Add data to the database <? Phpheader ("Content-type: text/html; charset = utf-8"); // ----------------------- connect to the database --------------------------- include_once "connect. php "; // ------------------------- connect data to the database ------------------ $ time = time (); $ SQL =" insert into user (username, password, email, sex, txt, 'time ') value ('{$ _ POST ['username']}', '{$ _ POST ['password']}', '{$ _ POST ['email']} ',' {$ _ POST ['sex']} ',' {$ _ POST ['txt ']}', '{$ time}') "; $ res = mysql_quer Y ($ SQL); header ("location: hello. php");?>

4. return to the background interface

<? Phpheader ("Content-type: text/html; charset = utf-8"); // ----------------------- connect to the database ------------------------------ include_once "connect. php "; // -------------------- query database -------------------------------- $ query =" select * from user "; $ result = mysql_query ($ query); if (! $ Result) {die ("cocould not to the database
". Mysql_error ();} // --------------------- encapsulate the function --------------------------- // This function writes the database data into the array form function result2Arr ($ result) {while ($ result_row = mysql_fetch_assoc ($ result) {$ arr [] = $ result_row;} return $ arr ;}$ arr = result2Arr ($ result ); foreach ($ arr as $ key => $ value) {echo" "; Echo"
"; Echo" "; Echo" "; Echo" "; Echo" "; Echo" "; Echo" "; Echo" "; Echo" "; Echo" "; Echo" "; Echo"
". $ Value ['id']."". $ Value ['username']."". $ Value ['password']."". $ Value ['email ']."". $ Value ['sex']."". $ Value ['txt ']."". Date ('Y-m-d H: I: S', $ value ['Time'])."Modify and delete
";}?>

5. modify data

// When the user wants to modify the information, return to the page, which contains the information previously filled in 
  Document

<? Php shortde_once "connect. php "; $ SQL =" select * from user where id = '". $ _ GET ['id']. "'"; // echo "SQL :". $ SQL; (display the row to be modified) $ result = mysql_query ($ SQL, $ link); $ arr = result2Arr ($ result); // print_r ($ arr ); $ row = $ arr [0]; function result2Arr ($ result) {while ($ result_row = mysql_fetch_assoc ($ result) {$ arr [] = $ result_row ;} return $ arr ;}?> Registration page

// Save the modified information to the database <? Phpheader ("Content-type: text/html; charset = utf-8"); // Get the data submitted on the page through post $ data =$ _ POST; // print_r ($ data); include_once "connect. php "; $ SQL =" update 'user' set username = '{$ data ['username']}', password = '{$ data ['password']}', email = '{$ data ['email']} ', sex =' {$ data ['sex']} ', txt = '{$ data ['txt']} 'where id =' {$ data ['id']} '"; echo $ SQL; $ res = mysql_query ($ SQL, $ link); if ($ res) {header ("Location: hello. php "); // echo" al Ert ('modified successfully') ";} else {header (" Location: update1.php? Id = ". $ data ['id']); // echo" alert ('modification failed') ";}?>

6. delete data

// Delete data in the database <? Phpheader ("Content-type: text/html; charset = utf-8"); include_once 'connect. php '; $ SQL = "delete from user where id = '". $ _ GET ['id']. "'"; $ sus = mysql_query ($ SQL, $ link); if ($ sus) {header ("location: hello. php ");} else {echo" alert ('deletion failed') ";}?> // If you want to delete Li Si, Clicking delete will automatically jump to the background page, and the data in the database will also be deleted.

The above is all the content of this article, hoping to help you learn.

Articles you may be interested in:
  • Verify the php code of the user name before registering the page
  • Use Php to write the instance code for Email activation verification after registration
  • The php user registration page uses js for form verification of specific instances
  • A complete example of ThinkPHP user registration logon message
  • PHP + Ajax check whether an instance exists at user name or email registration
  • PHP + jQuery registration module development details
  • Improvement of PHP + jQuery registration module (1): Saving the verification code to the SESSION
  • PHP + jQuery registration module improvement (2): mailbox activation
  • Php + mysql implementation of user registration and login methods
  • Php sends text message verification code to complete registration

Examples in this article share with you how to add, delete, modify, and query the registration page by connecting to the database in PHP for your reference...

Related Article

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.