[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:
Id |
Username |
Password |
"; Echo"
$ {Row ["id"]} | "; Echo"
$ {Row ["username"]} | "; Echo"
$ {Row ["password"]} | "; Echo"
";}// The query is complete. remember to visit mysql_close ($ con);?>
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