Adding, deleting, modifying, and querying php Data Access, and adding and deleting php Data Access

Source: Internet
Author: User
Tags learn php programming

Adding, deleting, modifying, and querying php Data Access, and adding and deleting php Data Access

Add, delete, modify, query, and perform small exercises.

1. view the news page ----- Homepage

<Html> 

  

Ii. Publish a news page ----- add content

<Html> 

  

Processing of submitted content:

<? Php $ newsid =$ _ POST ["newsid"]; $ title =$ _ POST ["title"]; $ author =$ _ POST ["author"]; $ source = $ _ POST ["source"]; $ content = $ _ POST ["content"]; $ time = date ("Y-m-d ", time (); $ db = new MySQLi ("localhost", "root", "", "mydb ");! Mysqli_connect_error () or die ("contact failed! "); $ SQL =" insert into news values ('{$ newsid}', '{$ title}', '{$ author}', '{$ source }', '{$ content}', '{$ time}') "; $ result = $ db-> query ($ SQL); if ($ result) {header (" location: xinwen. php ");} else {echo" failed to add news! ";}

3. Delete content

<? Php $ newsid = $ _ GET ["newsid"]; $ db = new MySQLi ("localhost", "root", "", "mydb ");! Mysqli_connect_error () or die ("connection failed! "); $ SQL =" delete from news where newsid = '{$ newsid}' "; $ result = $ db-> query ($ SQL); if ($ result) {header ("location: ChaKan. php ") ;}else {echo" failed to delete data ";}?>
  

4. Modify the news page-Modify the news content and submit it for viewing

<Html> 

  

After the modification is submitted, process the modification:

<? Php $ newsid =$ _ POST ["newsid"]; $ title =$ _ POST ["title"]; $ author =$ _ POST ["author"]; $ source = $ _ POST ["source"]; $ content = $ _ POST ["content"]; $ time = date ("Y-m-d ", time (); $ db = new MySQLi ("localhost", "root", "", "mydb ");! Mysqli_connect_error () or die ("contact failed! "); $ SQL =" update news set title = '{$ title}', author = '{$ author}', source = '{$ source }', content = '{$ content}', time = '{$ time}' where newsid = '{$ newsid }'"; $ result = $ db-> query ($ SQL); if ($ result) {header ("location: Update. php ");} else {echo" failed to modify data! ";}

The above is all the content of this article. I hope it will help you learn php programming.

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.