初写留言板

第一次的留言板

1
2
第一次写留言板,真的好辛苦,几分钟看懂的代码自己一个个敲花了一下午
体会到开发的痛苦了,希望自己以后可以多写东西出来

index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!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.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
header("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.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
header("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.php

1
2
3
4
5
6
7
8
9
10
11
<?php
header("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.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!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>
<?php
header("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>