Add, modify, and delete basic database operation code (1/4) _ PHP Tutorial

Source: Internet
Author: User
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
?>























While ($ row = $ db-> fetch_array ($ query )){?> }?>
Total number of records: ---- Add personnel
Login account Login Password Problem Answer Time added Operation
& Page = "> Delete/
& Page = "> Modify





}
?>



1 2 3 4

Success ,...

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.