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:
1 Create Database form; 2 3 use form; 4 5 CREATE TABLE ' message ' (6 ' id ' tinyint (1) Not NULL auto_increment, 7 ' user ' varchar (25) Not NULL, 8 ' title ' varchar (no null), 9 ' content ' tinytext not null,10 ' lastdate ' date not null,11 PR Imary KEY (' id ') engine=innodb DEFAULT CHARSET=GBK auto_increment=1;
conn.php
1 <?php2 $conn = @ mysql_connect ("localhost", "root", "") or Die ("Database link Error"), 3 mysql_select_db ("form", $conn); 4 mysql_qu Ery ("Set names ' GBK '"); 5?>
add.php
1 <?php 2 include ' conn.php '; 3 if ($_post[' submit ']) {4 $sql = "INSERT into message (id,user,title,content,lastdate) VALUES (NULL, ' $_post[user] ', ' $_p Ost[title] ', ' $_post[content] ', now ()) "; 5 mysql_query ($sql); 6 7//page jump, implemented in JavaScript 8 $url = "list.php"; 9 echo "<script language= ' javascript ' type= ' Text/javascript ' >", echo "window.location.href= ' $url '"; 11 echo "</script>",}13? >14 <script type= "Text/javascript" >15 function checkpost () {if (addform.us er.value== "") {alert ("Please enter user name"), AddForm.user.focus (), Return false;21}22 if (addform . title.value.length<5) {alert ("title cannot be less than 5 characters"), AddForm.title.focus (), and return false;26 }27}28 </script>29 <form name= "AddForm" method= "POST" action= "add.php" onsubmit= "return Checkpost ();" >30 User: <input type= "text" name= "user"/><br/>31 title: <input type= "text" name= "title"/><br/>32 content: <textarea name= "Content" rows= "8" cols= "" ></textarea><br/>33 <input type= "Submit" NAME= " Submit "value=" Add "/></form>
list.php
1 <?php 2 include ' conn.php '; 3?> 4 <?php 5 echo "<div align= ' center ' ><a href= ' add.php ' > Continue adding </a></div>"; 6?> 7 <table width=500 border= "0" align= "center" cellpadding= "5" cellspacing= "1" bgcolor= "#add3ef" > 8 <?php 9 $sql = "SELECT * from the message order by id", $query =mysql_query ($sql), one while ($row =mysql_fetch_array ($query)) {?> <tr bgcolor= "#eff3ff" >15 <td> title: <font color= "Red" ><?= $row [title]?></font> Users: <font color= "Red" ><?= $row [user]? ></font><div align= "right" ><a href= "preedit.php?id= <?= $row [id]?> "> Editor </a> | <a href=" delete.php?id=<?=$ row[id]?> "> Delete </a></div></td>16 </tr>17 <tr bgcolor=" #ffffff ">18 <td> content: & lt;? = $row [content]?></td>19 </tr>20 <tr bgcolor= "#ffffff" >21 <td><div align= "right" > published Date: <?= $row [lastdate]?></div></td>22 </tr>23 <?php}?>24 </table>
delete.php
1 <?php 2 include ' conn.php '; 3 $id = $_get[' id ']; 4 $query = "Delete from message where id=". $id; 5 mysql_query ($query); 6?> 7 <?php 8//page jump, implemented in JavaScript 9 $url = "list.php"; echo "<script language= ' javascript ' type= ' text/j Avascript ' > ", one echo" window.location.href= ' $url ' ", echo" </script> ";?>
preedit.php
1 <?php 2 include ' conn.php '; 3 $id =$_get[id]; 4 $query = "SELECT * FROM message WHERE id =". $id; 5 $result =mysql_query ($query); 6 while ($rs =mysql_fetch_array ($result)) {7?> 8 <form method= "POST" action= "postedit.php" > 9 <input Type= "hidden" name= "id" value= "<?= $rs [id]?>" >10 User: <input type= "text" name= "user" value= "<?= $rs [ User]?> "/><br/>11 title: <input type=" text "name=" title "value=" <?= $rs [title]?> "/><br/ >12 content: <textarea name= "Content" rows= "8" cols= "><?= $rs [content]?></textarea><br/ >13 <input type= "Submit" name= "Submit" value= "edit"/>14 </form>15 <?php}?>
postedit.php
1 <?php 2 include ' conn.php '; 3 $query = "Update message set user= ' $_post[user] ', title= ' $_post[title] ', content= ' $_post[content] ' where id= ' $_post[id ]‘"; 4 mysql_query ($query); 5?> 6 <?php 7//page jump, implemented in JavaScript 8 $url = "list.php"; 9 echo "<script language= ' javascript ' type= ' text/j Avascript ' >, ' window.location.href= ' $url ', echo ' </script> ';?>
PHP Development _ Message board CRUD (increase, delete, change, check) operation