[Php] addition, deletion, modification, and query of databases and interaction between php and javascript

Source: Internet
Author: User
[Php] adding, deleting, modifying, and querying databases, and interacting with php and javascript using languages to operate databases are the top priority. if you do not know how to operate a database in a language, then you still haven't learned this language.

Php database operations are not difficult

At the same time, php values can be controlled with javascript scripts,

Generally, the php value is passed to javascript and will not be reversed.


I. basic objectives

First, there is a user information table in mysql,

The fields are id, username, and password respectively,

Open the page dbselect. php and use php to check the entire user table:


Then, insert a column of data and input data to insert the data to the user table in mysql.


In the modify data column, the first drop-down menu is created using javascript,

The drop-down list based on the amount of data in the table.


The second drop-down menu allows you to select the columns to be modified

The third input box is to ask the user to enter the value to be modified.


The reason why data is not deleted is that the operation to delete data is similar to modifying data. The second reason is that data is not deleted in the auto-increment table, and only the key value is set to hide the data.


II. basic ideas

The program entry is dbselect. php. the database operation process is two new pages, one is dbinsert. php and the other is dbupdate. php. after these two pages operate on the database, they are immediately returned through javascript.



III. Production process

(1) dbselect. php

It is also the most complex page in this implementation process.

 DbselectUser table:
 
  "; Echo" 
   "; Echo" 
    "; Echo" 
    "; Echo" 
   ";}// The query is complete. remember to visit mysql_close ($ con);?> 
  
Id Username Password
$ {Row ["id"]}$ {Row ["username"]}$ {Row ["password"]}

Insert data: modify data:

For details about how javascript controls html nodes, refer to my previous article "add, delete, modify, and query of [JavaScript] webpage nodes" (click to open the link)


(2) dbinsert. php

 Dbinsert. php
 Script alert ("added successfully"); window. location. href = "dbselect. php"; script

(3) dbupdate. php

The logic is exactly the same as that of dbinsert. php, but the query statement of mysql_query has changed from the insert into statement to the update statement.

 Untitled Document
 Script alert ("modified successfully"); window. location. href = "dbselect. php"; script

The above is the entire production process

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.