PHP Development Message board to increase, delete, change, check operation

Source: Internet
Author: User
This article to you to share the content is the PHP development message board, delete, change, check operation, has a certain reference value, the need for friends can refer to

PHP Learning, to open a message book as PHP's entry information is still good.

Project structure:

Add Page: Description: Here only focus on the operation, the interface of the artist did not work, I hope you understand ...

List page:

Modify Page:

SQL required in the project:

Copy the Code code as follows:

Create Database form; Use form; CREATE TABLE ' message ' (' ID ' tinyint (1) NOT NULL auto_increment, ' user ' varchar (+) ' NOT null ', ' title ' varchar (\) Not NUL L, ' content ' tinytext not null, ' lastdate ' date not NULL, PRIMARY KEY (' id ')) engine=innodb DEFAULT CHARSET=GBK auto_incr Ement=1; conn.php

Copy the Code code as follows:

<?php $conn = @ mysql_connect ("localhost", "root", "") or Die ("Database link error"); mysql_select_db ("form", $conn); mysql_query ("Set names ' GBK '");?> add.php

Copy the Code code as follows:

<?php include ' conn.php '; if ($_post[' submit ']) {$sql = "INSERT into message (id,user,title,content,lastdate) VALUES (NULL, ' $_post[user] ', ' $_post [title] ', ' $_post[content] ', now ()) "; mysql_query ($sql); Page jump, the implementation of javascript $url = "list.php"; echo "<script language= ' javascript ' type= ' text/javascript ' >"; echo "window.location.href= ' $url '"; echo "</script>"; }?> <script type= "Text/javascript" > Function checkpost () {if (addform.user.value== "") {alert ("Please enter username"); AddForm.user.focus (); return false; } if (addform.title.value.length<5) {alert ("title cannot be less than 5 characters"); AddForm.title.focus (); return false;}} </script> <form name= "AddForm" method= "POST" action= "add.php" onsubmit= "return Checkpost ();" > User: <input type= "text" name= "user"/><br/> title: <input type= "text" name= "title"/><br/> Content: &L T TEXTAREA name= "Content" rows= "8" cols= "></textarea><br/> <input type=" Submit "name=" Submit " Value= "Add"/></form> list.php 

Copy the code code as follows:

<?php include ' conn.php ';?> <?php echo "<p align= ' center ' ><a href= ' add.php ' > Continue adding </a></p > ";?> <table width=500 border=" 0 "align=" center "cellpadding=" 5 "cellspacing=" 1 "bgcolor=" #add3ef "> <? PHP $sql = "SELECT * from the message order by ID"; $query =mysql_query ($sql); while ($row =mysql_fetch_array ($query)) {?> <tr bgcolor= "#eff3ff" > <td> title: <font color= "Red" >< ? = $row [title]?></font> User: <font color= "Red" ><?= $row [user]? ></font><p align= "Right"  ><a href= "preedit.php?id=<?= $row [id]?>" > Edit </a> | <a href= "delete.php?id=<?= $row [id]?>" > Delete </a></p></td> </tr> <tr bgcolor= "# FFFFFF > <td> content: <?= $row [content]?></td> </tr> <tr bgcolor= "#ffffff" > <td> <p align= "Right" > Date Published: <?= $row [lastdate]?></p></td> </tr> <?php}?> </table > delete.php

Copy the Code code as follows:

<?php include ' conn.php '; $id = $_get[' id ']; $query = "Delete from message where id=". $id; mysql_query ($query);?> <?php//page jump, implemented in javascript $url = "list.php"; echo "<script language= ' javascript ' type= ' text/javascript ' >"; echo "window.location.href= ' $url '"; echo "</script>";?> preedit.php

Copy the Code code as follows:

<?php include ' conn.php '; $id =$_get[id]; $query = "SELECT * FROM message WHERE id =". $id; $result =mysql_query ($query); while ($rs =mysql_fetch_array ($result)) {?> <form method= "POST" action= "postedit.php" > <input type= "hidden "Name=" id "value=" <?= $rs [id]?> "> Users: <input type=" text "name=" user "value=" <?= $rs [user]?> "/> <br/> Title: <input type= "text" name= "title" value= "<?= $rs [title]?>"/><br/> content: <textarea NAME = "Content" rows= "8" cols= "><?= $rs [content]?></textarea><br/> <input type=" Submit "Name=" Submit "value=" edit "/> </FORM> <?php}?> postedit.php

Copy the Code code as follows:

<?php include ' conn.php '; $query = "Update message set user= ' $_post[user] ', Title= ' $_post[title] ', content= ' $_post[content] ' where id= ' $_post[id] ' "; mysql_query ($query);?> <?php//page jump, implemented in javascript $url = "list.php"; echo "<script language= ' javascript ' type= ' text/javascript ' >"; echo "window.location.href= ' $url '"; echo "</script>"; "; 

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.