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.