PHP Connection database implementation of the registration page to change the operation, PHP additions and deletions _php tutorial

Source: Internet
Author: User

PHP Connection database to implement the registration page additions and deletions to check the operation, PHP additions and deletions


The example of this article for everyone to share the PHP connection database implementation of the registration page of the method of adding and deleting, for your reference, the specific content as follows

1. Connect to the database

<?php//local Test $host = ' 127.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 database library name of the connection mysql_select_db ("my"); Set character encoding utf8 mysql_set_charset (' utf8 ');? >

2. Registration page (HTML page)

 
 
  Document

Registration page

3. Display the registration data in the database

Add data to the database <?phpheader ("content-type:text/html; Charset=utf-8 "),//-----------------------Connection Database---------------------------include_once" connect.php ";//--------- ----------------connect the 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_query ($sql), header ("location:hello.php"); >

4. Back to the background interface

<?phpheader ("content-type:text/html; Charset=utf-8 "),//-----------------------Connection Database------------------------------include_once" connect.php ";//------ --------------Query Database--------------------------------$query = "SELECT * from user"; $result =mysql_query ($query); if (!$ Result) {die ("could not to the database
". Mysql_error ());} -------------------encapsulation Function-----------------------------//This function writes the data of the database as an 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 Delete
";}? >

5. Modify the data

When the user wants to modify the information, return to the page, the page contains the information previously filled 
 
  Document<?php include_once "connect.php"; $sql = "SELECT * from user where id= '". $_get[' id ']. "'"; echo "sql:". $sql;(show which line to modify) $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

Deposit the modified information into the database <?phpheader ("content-type:text/html; Charset=utf-8 ");//Get page submission data information via 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 "alert (' Modify success ')";} else{header ("location:update1.php?id=". $data [' id ']);//echo "alert (' modification failed ')";}? >

6. Delete data

Delete the 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 (' delete failed ')";}? >//to delete John Doe, click Delete, will automatically jump to the background page, the data in the database is also deleted

The above is the whole content of this article, I hope that everyone's study has helped.

Articles you may be interested in:

    • PHP code to verify the existence of the user name before registering the page
    • Use PHP to write an instance code for email activation verification after registration
    • PHP user registration page using JS to form validation specific instances
    • thinkphp User Registration Login Message Complete Example
    • Php+ajax detect if a user name or message registration is already present in the instance tutorial
    • Php+jquery Registration Module Development detailed
    • Improvement of Php+jquery Registration Module (i): Verification code stored in session
    • Improvement of Php+jquery Registration Module (II): Mailbox activation
    • PHP+MYSQL realization of User Registration login method
    • PHP to send SMS verification code to complete the registration function

http://www.bkjia.com/PHPjc/1114240.html www.bkjia.com true http://www.bkjia.com/PHPjc/1114240.html techarticle PHP Connection Database Implementation of the registration page to delete and change the operation, PHP additions and deletions in this article for everyone to share the PHP connection database to implement the registration page of the deletion and modification of the method, for your reference ...

  • 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.