开学以来一直都很想做个留言板,最近比较闲,花了点时间学了学,做出了以后觉得这个是如此的简单,做的时候还问了他们科网的几个好多问题呢……有人带就是学的快多了……
目录:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>目录</title>
</head>
<body background="images/121001L442-4.jpg">
<br><br><br><br>
<center>
<a href="liuyan1.php">进入留言</a>
<a href="xiugai1.php">修改留言</a>
<a href="liulan1.php">浏览留言</a>
<a href="shouye1.php">返回首页</a>
</body>
</html>
处理:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>处理页面</title>
</head>
<body background="images/2009102315454340552.jpg">
<?php
$name=$_POST["name"];
$sex=$_POST["sex"];
$email=$_POST["email"];
$content=$_POST["content"];
if($name=="")
{
echo "<script> alert('~亲!你还没有填写姓名呢。。。。。')</script>";
}
if($email=="")
{
echo "<script> alert('~亲!你还没有写email呢。。。。。')</script>";
}
if($content=="")
{
echo "<script> alert('~亲!你还没有留言呢。。。。。')</script>";
}
else
{
mysql_connect("localhost","root","")or die(mysql_error());
mysql_select_db("liuyan")or die("数据库连接失败!".mysql_error());
mysql_query("set names 'utf-8'");
$sql=mysql_query("INSERT INTO `liuyan`.`liuyanbiao1` (
`id` ,
`name` ,
`sex` ,
`email` ,
`content` ,
`time`
)
VALUES (
NULL,'$name','$sex','$email','$content',NOW())"
);
}
if($sql)
{
echo "<script language='javascript'>alert('~亲!留言成功!');histroy.back</script>";
}
else
{
echo "<script>alert('~亲!留言失败!)</script>";
}
?>
<br><br><br>
<center>
<img src="images/u=2046914711,2667007643&fm=11&gp=0.gif">
<a href='liulan1.php'>留言浏览</a>
</body>
</html>
首页:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>留言板首页</title>
</head>
<body background="images/11203376278d250b98o.jpg">
<br><br><br><br><br>
<center>
<?php
echo "<strong> 您好!欢迎来到留言首页! </strong>";
?>
<p>
<img src="images/u=495729995,630851958&fm=13&gp=0.gif"><a href="liuyan1.php">进入留言 </a>
</body>
</html>
更新:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>留言更新页面</title>
</head>
<body>
<?php
$id=$_GET['id'];
$name=$_POST["name"];
$sex=$_POST["sex"];
$email=$_POST["email"];
$content=$_POST["content"];
if($name=="")
{
echo "<script> alert('~亲!你还没有填写姓名呢。。。。。')</script>";
}
if($email=="")
{
echo "<script> alert('~亲!你还没有写email呢。。。。。')</script>";
}
if($content=="")
{
echo "<script> alert('~亲!你还没有留言呢。。。。。')</script>";
}
else
{
mysql_connect("localhost","root","")or die(mysql_error());
mysql_select_db("liuyan")or die("数据库连接失败!".mysql_error());
mysql_query("set names 'utf-8'");
$sql=mysql_query("UPDATE `liuyan`.`liuyanbiao1` SET `id` = '$id',
`name` = '$name',`sex` = '$sex',`email` = '$email',`content` = '$content' WHERE `liuyanbiao1`.`id` ='$id' ;
");
}
if($sql)
{
echo "<script language='javascript'>alert('~亲!修改成功!');histroy.back</script>";
}
else
{
echo "<script>alert('~亲!修改失败!)</script>";
}
?>
<br><br><br>
<center>
<img src="images/u=2046914711,2667007643&fm=11&gp=0.gif">
<a href='liulan1.php'>留言浏览</a>
?>
</body>
</html>
删除:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>删除页面</title>
</head>
<body background="images/21512BW7-6.jpg">
<br><br><br><br>
<center>
<?php
$id=$_GET['id'];
mysql_connect("localhost","root","");
mysql_select_db("liuyan") or die("~连接失败!".mysql_error());
mysql_query("set names uft-8");
$sql="delete from `liuyanbiao1` where `liuyanbiao1`.`id`='$id';";
if(mysql_query($sql))
{
echo "~亲!删除成功!";
}
else
{
echo "删除失败!";
}
?>
<img src="images/u=495729995,630851958&fm=13&gp=0.gif">
<a href="mulu1.php">返回目录</a>
</body>
</html>
修改:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>修改页面</title>
</head>
<body background="images/f4b41552fd8c7ec28c543095.jpg" >
<br><br><br><br>
<center>
<?php
$id=$_GET[id];
mysql_connect("localhost","root","") or die("连接失败!".mysql_error());
mysql_select_db("liuyan")or die("连接数据库失败!".mysql_error());
mysql_query("set names utf-8");
$array=mysql_fetch_array(mysql_query("SELECT * FROM `liuyanbiao1` WHERE `liuyanbiao1`.`id`='$id'"));
?>
<table border="1" cellspacing="0" cellpadding="1" width="744" height="500" style="margin-left:20px">
<form action="update.php?id=<?php echo $array['id'];?>" method="post">
<p>
<strong>姓名:</strong>
<input type="text" name="name" value="<?php echo $array['name']; ?>"/>
<p>
<strong>性别:</strong>
<?php
if($array['sex']=="男")
{
?>
<input type='radio' name="sex" value="男" checked="checekd">男
<input type="radio" name="sex" value="女" checked>女
<?php
}else{
?>
<input type='radio' name="sex" value="男" checked>男
<input type="radio" name="sex" value="女" checked="checked">女
<?php
}
?>
<p>
<strong>邮箱:</strong>
<input type="text" name="email" value="<?php echo $array['email']; ?>"/>
<p>
<strong>留言内容:</strong>
<textarea rows="10" cols="60" style="background-color:#FFF" name="content"><?php echo $array['content']; ?></textarea>
<p>
<input type="submit" name="submit" value="提交"/ >
<input type="reset" name="reset" value="重置"/>
<a href="shouye1.php">返回首页</a>
</form>
</body>
</html>
浏览:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>浏览页面</title>
</head>
<body background="images/1_101117004925_1.jpg">
<a href="shouye1.php">返回首页</a>
<?php
mysql_connect("localhost","root","") ;
mysql_select_db("liuyan") or die("~连接失败!".mysql_error());
mysql_query("set names utf-8");
$result=mysql_query("SELECT * FROM `liuyanbiao1` ORDER BY `id` DESC ");
?>
<table border="1" width="1000" cellspacing="0" background="images/20121231161823.png" style="margin-top:40px;">
<tr>
<td>ID</td>
<td>姓名</td>
<td>性别</td>
<td>邮箱</td>
<td>留言内容</td>
<td>时间</td>
<td>操作</td>
</tr>
<?php
while($array=mysql_fetch_array($result))
{
?>
<tr>
<td><?php echo $array['id']; ?> </td>
<td><?php echo $array['name']; ?></td>
<td><?php echo $array['sex']; ?></td>
<td><?php echo $array['email']; ?></td>
<td><?php echo $array['content']; ?></td>
<td><?php echo $array['time']; ?></td>
<td><a href="shanchu1.php?id=<?php echo $array['id'];?>"> 删除 </a><a href="xiugai1.php?id=<?php echo $array['id'];?>">修改</a></td>
</tr>
<?php
}
?>
</table>
</body>
</html>