Papan mesej pembangunan papan mesej PHP selesai
fail conn.php
<?php $conn = @ mysql_connect("localhost", "root", "123456789") or die("數(shù)據(jù)庫(kù)鏈接錯(cuò)誤"); mysql_select_db("bbs", $conn); mysql_query("set names 'utf8'"); //使用utf-8中文編碼; ?>
tambah fail.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link href="css.css" rel="stylesheet" type="text/css"> <title>Title</title> <?php include ("add.php")?> </head> <script> function CheckPost() { if(myform.user.value=="") { alert("請(qǐng)?zhí)顚?xiě)用戶(hù)"); myform.user.focus(); return false; } if (myform.title.value.length<5) { alert("標(biāo)題不能少于5個(gè)字符"); myform.title.focus(); return false; } if (myform.content.value=="") { alert("內(nèi)容不能為空"); myform.content.focus(); return false; } } </script> <body> <b> <a href="list.php">瀏覽留言</a> </b> <hr size=1> <form action="add.php" method="post" name="myform" onsubmit="return CheckPost();"> 用戶(hù):<input type="text" size="10" name="user"/><br> 標(biāo)題:<input type="text" name="title" /><br> 內(nèi)容:<textarea name="content"></textarea><br> <input type="submit" name="submit" value="發(fā)布留言" /> </form> </body> </html>
fail css.css
td { line-height: 16pt; font-size: 10pt; font-family: "Verdana", "Arial", "Helvetica", "sans-serif"; } a:link { text-decoration: none; color: #000000; } body { font-size: 10pt; line-height: 13pt; background-color: #ECF5FF; } textarea { font-size: 8pt; font-family: "Verdana", "Arial", "Helvetica", "sans-serif"; border: 1px solid #999999; padding: 5px; } form { margin: 0px; padding: 0px; } .textdrow { color:#666666; filter: DropShadow(Color=white, OffX=1, OffY=1, Positive=1); } .p { text-indent: 24px; }
tambah.php
<?php include ("conn.php"); if ($_POST['submit']){ $sql="insert into message(id,user,title,content,lastdate) ". "values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())"; mysql_query($sql); echo "<script>alert('添加成功');history.go(-1)</script>"; } ?>
fail list.php
<!DOCTYPE html> <html lang="utf-8"> <head> <link href="css.css" rel="stylesheet" type="text/css"> </head> <?php include ("conn.php"); ?> <table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef" > <?php $sql="select * from message order by id desc"; $query=mysql_query($sql); while($row=mysql_fetch_array($query)){ ?> <tr bgcolor="#eff3ff"> <td><font color="red">標(biāo)題:</font><?php echo $row['title'];?> <font color="red">用戶(hù):</font><?php echo $row['user'];?><div align="right"><a href="del.php?id=<?php echo $row['id'];?>">刪除</a></div></td> </tr> <tr bgColor="#ffffff"> <td>發(fā)表內(nèi)容:<?php echo $row['content'];?></td> </tr> <tr bgColor="#ffffff"> <td><div align="right">時(shí)間:<?php echo $row['lastdate'];?></td> </tr> <?php } ?> <tr bgcolor="#f0fff0"> <td><div align="right"><a href="add.html">返回留言</a> </td> </tr> </table> </html>
fail del.php
<?php include 'conn.php'; $id = $_GET['id']; $query="delete from message where id=".$id; mysql_query($query); ?> <?php //頁(yè)面跳轉(zhuǎn),實(shí)現(xiàn)方式為javascript $url = "list.php"; echo "<script>"; echo "window.location.href='$url'"; echo "</script>"; ?>
Pergi ke ini papan mesej Penulisan pada asasnya telah selesai Artikel ini hanya berfungsi sebagai titik permulaan Sebagai contoh yang paling mudah dan paling asas, pembaca boleh terlebih dahulu memahami cara menggunakan PHP untuk mengendalikan pangkalan data dan menggabungkannya menjadi contoh yang mudah.