This article mainly introduces in detail the addition, deletion, modification and query of the PHP database, as well as the interaction between PHP and JavaScript. It has a certain reference value. Interested friends can refer to it.
Use Language operation of databases is a top priority. If you don’t know how to operate a database in a language, then you still haven’t learned the language.
It is not difficult to operate the database with PHP
At the same time, the value of php can also be controlled with the JavaScript script
Generally, the value of php is passed to javascript. It will not be done the other way round
1. Basic goals
First, there is a user information table user in mysql, the fields in it are id, username and password. Open the web page dbselect.php, first use php to find out the entire user table:
Then, insert a column of data, enter the data, and the data can be Insert into the user table in mysql
#In the column where the data is modified, the first drop-down menu is created through javascript. According to the How much data is given and how many drop-down options are given.
The second drop-down menu allows the user to select the column to be modified
The third input box is for the user to enter the value to be modified
As for why the data is not deleted, it is because the operation of deleting data is similar to modifying data, and the second reason is that data is generally not deleted in auto-increment tables. Yes, just set the key value to hide this data
2. Basic idea
The program entrance is dbselect.php, and the process of operating the database is two new Pages, one is dbinsert.php and the other is dbupdate.php. After these two pages operate the database, they will be returned immediately through javascript.
3. Production process
(1) dbselect.php
It is also the most complicated page in this implementation process
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
For details on how javascript controls html nodes, you can refer to the "[ JavaScript] Article "Add, delete, modify and check web page nodes" (click to open the link)
(2) dbinsert.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
( 3) The logic of dbupdate.php
is exactly the same as that of dbinsert.php, except that the query statement of mysql_query has changed from the insert into statement to the update statement
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
The above is the entire production process.
Related recommendations:
php database cache implementation ideas
##PHP database processing encapsulation class
The above is the detailed content of Addition, deletion, modification and query of PHP database Interaction between PHP and JavaScript. For more information, please follow other related articles on the PHP Chinese website!