Basic operation code for adding, modifying, and deleting databases (14 ). Adding, modifying, and deleting basic database operation code is a suitable tutorial for beginners of php. We use a simple instance to add, modify, and delete databases, adding, modifying, and deleting basic database operation code is a suitable tutorial for beginners of php. We use a simple instance to add, modify, and delete databases, this gives you a more systematic understanding of the key points of php mysql database operations.
Add, modify, and delete basic operation codes for database tutorials
This is a relatively suitable php Tutorial for beginners. We use a simple instance to add, modify, and delete databases, this gives you more information about the database operations in the php mysql tutorial.
*/
Require_once ('Common. php ');
$ Action = $ _ get ['action'];
?>
Talent List
If ($ action = 'ADD '){
?>
}
Elseif ($ action = 'save '){
$ Login = isset ($ _ post ['login'])? $ _ Post ['login']: '';
$ Pws = isset ($ _ post ['pws '])? $ _ Post ['pws ']: '';
$ Question = isset ($ _ post ['question '])? $ _ Post ['question ']: '';
$ Answer = isset ($ _ post ['answer'])? $ _ Post ['answer']: '';
$ SQL = "insert into person (login, pws, question, answer)
Values ('$ login',' $ pws ',' $ question ',' $ answer ')";
$ Db-> query ($ SQL );
Forward ('publishing successfully', 'href ', 'personlist. php ');
}
Elseif ($ action = 'Del '){
$ Person_id = $ _ get ['person _ id'];
$ Page = $ _ get ['Page'];
$ SQL = "delete from person where person_id = '$ person_id '";
$ Db-> query ($ SQL );
Forward ('deleted successfully', 'href ', 'personlist. php? Page = '. $ page );
}
Elseif ($ action = 'editsave '){
$ Person_id = isset ($ _ post ['person _ id'])? $ _ Post ['person _ id']: '';
$ Page = isset ($ _ post ['Page'])? $ _ Post ['Page']: '';
$ Login = isset ($ _ post ['login'])? $ _ Post ['login']: '';
$ Pws = isset ($ _ post ['pws '])? $ _ Post ['pws ']: '';
$ Question = isset ($ _ post ['question '])? $ _ Post ['question ']: '';
$ Answer = isset ($ _ post ['answer'])? $ _ Post ['answer']: '';
$ SQL = "update person set login = '$ login', pws =' $ pws ', question =' $ question ', answer = '$ answer' where person_id = '$ person_id '";
$ Db-> query ($ SQL );
Forward ('modified successfully', 'href ', 'personlist. php? Page = '. $ page );
}
Elseif ($ action = 'edit '){
$ Person_id = $ _ get ['person _ id'];
$ Page = $ _ get ['Page'];
$ SQL = "select * from person where person_id = '$ person_id '";
$ Query = $ db-> query ($ SQL );
$ Row = $ db-> fetch_array ($ query );
$ Login = $ row ['login'];
$ Pws = $ row ['pws '];
$ Question = $ row ['question '];
$ Answer = $ row ['answer'];
?>
}
Else {
$ Page = isset ($ _ get ['Page'])? Intval ($ _ get ['Page']): 1;
$ Num = 5;
$ SQL = "select * from person ";
$ Query = $ db-> query ($ SQL );
$ Totalnum = $ db-> num_rows ($ query); // The total number of records
$ Pagenum = ceil ($ totalnum/$ num); // total number of pages
$ Offset = ($ page-1) * $ num;
$ SQL = $ SQL. "limit $ offset, $ num ";
$ Query = $ db-> query ($ SQL); // retrieve records
?>
| Total number of records: ---- Add personnel |
| Login account |
Login Password |
Problem |
Answer |
Time added |
Operation |
While ($ row = $ db-> fetch_array ($ query )){?>
|
|
|
|
|
& Page = "> Delete/
& Page = "> Modify |
}?>
}
?>
1 2 3 4
Success ,...