Submit the content of the page and add it to the database:
<?PHP//Var_dump ($_post);$title=$_post["title"];$Author=$_post["Author"];$source=$_post["Source"];$content=$_post["Content"];$time= Time();$db=NewMysqli ("localhost", "root", "123", "Newssystem");$sql= "INSERT into news values (0, ' {$title}‘,‘{$Author}‘,‘{$source}‘,‘{$content} ', now ()) ";Echo $sql;$result=$db->query ($sql);if($result){ Echo"<script type= ' text/javascript ' >window.location.href= ' fabuxinwen.php ';</script> ';}Else{ Echo"Add failed! ";}
Display the contents of the database in the Web page:
//first add a table to the page and set the column name<tableclass= "Table table-bordered" > <thead> <tr> <th>id</th> <th>title</th> <th>author</th> <th>source</th> <th>Date</th> <th>update</th> <th>delete</th> </tr> </thead>//The contents of the table are stored in the database and displayed<tbody> <?PHP$db=NewMysqli ("localhost", "root", "123", "Newssystem"); $sql= "SELECT * FROM News"; $result=$db->query ($sql); if($result){ $arr=$result-Fetch_all (); foreach($arr as $v){ Echo"<tr> <td>{$v[0]}</td> <td>{$v[1]}</td> <td>{$v[2]}</td> <td>{$v[3]}</td> <td>{$v[5]}</td> <td> <a href= ' xiugai.php?newsid={$v[0]} ' ><button type= ' button ' class= ' btn btn-primary btn-sm ' > Modify </button></a> </td> <td> <a href= ' shanchu.php?title={$v[1]} ' onclick=\ ' return confirm (' Confirm delete? ') \ ">
<button type= ' button ' class= ' btn btn-primary btn-sm ' > Delete </button>
</a> </td> </tr>"; } } ?> </tbody></table>
To delete the data:
<?PHP$title=$_get["title"];$db=NewMysqli ("localhost", "root", "123", "Newssystem");$sql= "Delete from news where title= ' {$title}‘";$result=$db->query ($sql);if($result){ Header("location:chakan.php");}Else{ Echo"Delete failed!" ";}
If you implement bulk Delete:
First, precede each line of the list with a check box:
<td><input type= ' checkbox ' class= ' ck ' name= ' ck[] ' value= ' {$v [0]} '/>{$v [0]}</td>
Then, at the top of the list column, add a check box that can be selected all:
<input type= "checkbox" id= "Ckall"/>
Add JS code to achieve a full selection:
<script type= "Text/javascript" >var ckall = document.getElementById ("Ckall"); Ckall function() { var xz = Ckall. Checked; var ck = document.getelementsbyclassname ("ck"); for (var i=0;i<ck.length;i++) { ck[i]. checked = xz; }} </script>
Add the Bulk Delete button and then make it available to run the code for the next page:
<?PHP$arr=$_post["CK"];//Delete from info where code in (' P001 ', ' p002 ', ' p003 ')$str=implode("‘,‘",$arr);$sql= "Delete from info where code in (' {$str}‘)";$db=NewMysqli ("localhost", "root", "123", "MyDB");$result=$db->query ($sql);if($result){ Header("location:main.php");}Else{ Echo"Delete failed!" ";}
Can implement the bulk delete function.
Modification of data (need to apply both to add and delete):
First, the data to be modified is shown:
//Add a PHP code to the modified page you want to show<?PHP//Remove primary key value$newsid=$_get["NewSID"];//Read the data$db=NewMysqli ("localhost", "root", "123", "Newssystem");$sql= "SELECT * FROM news where newsid={$newsid}";$result=$db->query ($sql);$arr 1=$result-Fetch_row ();?>
It then displays the contents (assigning Values to the text box) within each piece of data, such as: <?php echo $arr 1[0]?>
To create a new PHP-only page:
<?PHP$newsid=$_post["NewSID"];$title=$_post["title"];$Author=$_post["Author"];$source=$_post["Source"];$content=$_post["Content"];$db=NewMysqli ("localhost", "root", "123", "Newssystem");$sql= "Update news set title= ' {$title} ', author= ' {$Author} ', source= ' {$source} ', content= ' {$content} ' where NewSID = {$newsid}";$result=$db->query ($sql);if($result){ Header("location:chakan.php");}Else{ Echo"The modification failed!" ";}
Implementing operations on the database in the PHP page