初写留言板 发表于 2018-12-23 | 阅读次数: 第一次的留言板12第一次写留言板,真的好辛苦,几分钟看懂的代码自己一个个敲花了一下午体会到开发的痛苦了,希望自己以后可以多写东西出来 index.html123456789101112131415161718192021<!DOCTYPE html><html><head><meta charset="utf-8"> <title>留言板</title></head><body><div align="center"><a href="list.php">浏览留言</a><br></div><form method="Post" action="add.php"><div align="center"><font> 用户:<br> </font> <input type="text" name="user" style="width=350px"><br> 标题:<br> <input type="text" name="title"><br> 内容:<br> <textarea name="content"></textarea><br> <input type="submit" name="" value="发布留言"></div></form></body></html> add.php12345678910111213141516<?phpheader("charset=utf8");include 'conn.php';$user = $_POST['user'];$title = $_POST['title'];$content = $_POST['content'];var_dump($user.$title.$content);$sql = "insert into message (user,title,content) values ('$user','$title','$content')";$row = mysql_query($sql);if($row){ echo "<script>alert('插入成功');window.history.go(-1);</script>";} ?> conn.php1234567891011121314<?phpheader("content-type:text/html;charset=utf-8");$host = 'localhost';$username = 'root';$password = 'root';$conn = mysql_connect($host,$username,$password);if(!$conn){ die("连接失败");}mysql_select_db("bbs",$conn);mysql_query("set names utf8"); ?> del.php1234567891011<?phpheader("content-type:text/html,charset='utf-8'");include('list.php');include('conn.php');$id = $_GET['id'];$sql = "delete from message where id=".$id;$result = mysql_query($sql);if($result){ echo "<script>alert('删除成功');window.location.href='list.php';</script>"; } ?> list.php12345678910111213141516171819202122232425262728293031323334353637<!DOCTYPE html><html><head> <title>留言查询</title> <meta charset="utf-8"></head><body><div align="center"><b align="center"><a href="add.html">添加留言</a></b></div><br><table align="center" border="1" width="50%" rules="all" bgcolor="#CCFF80"> <tr> <th>用户</th> <th>标题</th> <th>内容</th> </tr><?phpheader("content-type:text/html;charset=utf-8");include("conn.php");$sql = "select * from message order by id desc";$query = mysql_query($sql);//$row = mysql_fetch_array($query);//echo $row['id'];//var_dump($row); while($row=mysql_fetch_array($query)){ ?><tr> <td><a href="del.php?id=<?php echo $row['id'];?>">删除留言</a><?php echo $row['user']; ?></td> <td><?php echo $row['title'] ?></td> <td><?php echo $row['content'] ?></td></tr> <?php } ?></table></body></html> 打赏 微信支付 支付宝