一个简单的PHP+MySQL留言本程序,可是怎么都调试不出来啊!
页面可以运行,但是无法进行登录和留言!纠结死啦
总共六个页面,大为高手看看是不是哪里有问题啊!
一、index.php页面:
<html>
<head>
<title>欢迎使用简约不简单-我的留言本</title>
<style type=text/css>
td{
font-size:12px;
line-height:150%;
}
</style>
</head>
<body>
<table border=1 cellspacing=0 cellspadding=0
style="border-collapse:collapse" align=center width=400 bordercolor=black height="382">
<tr><td height=100 bgcolor=#6c6c6c style="font-size:30px;line-height:30px">
<font color=#ffffff face="黑体">简约不简单-我的留言本</font>
</td><tr>
<tr><td height=25>
<a href=send.php>[我要写留言]</a> <a href=login.php>[管理留言]</a>
</td></tr>
<tr><td height=200>
<?php
$id=mysql_connect("localhost","root","luxinluck123");
mysql_select_db("gbook",$id);
$query="select * from message ";
$result=mysql_query($query,$id);
if(mysql_num_rows($result)<1){
echo " 目前数据表中还没有任何留言!";
}else{
$totalnum=mysql_num_rows($result);
$pagesize=10;
$page=$_GET["page"];
if($page==""){
$page=1;
}
$begin=($page-1)* pagesize;
$totalpage=ceil($totalnum/$pagesize);
echo"<table border=0 width=95%><tr><td>";
$datanum=mysql_num_rows($result);
echo "共有留言".$totalnum."条。";
echo "每页".$pagesize."条,共".$totalpage."页<br>";
for($j=1;$j<=$totalpage;$j++){
echo "<a href=index.php?page=".$j.">[".$j."] </a>";
}
echo "<br>";
$query="SELECT * FROM message order by addtime desc limit
$begin,$pagesize";
$result=mysql_query($query,$id);
for($i=1;$i<$datanum;$i++){
$info=mysql_fetch_array($result,MYSQL_ASSOC);
echo"->[".$info['author']."]于".$info['addtime']."说:<br>";
echo" ".$info['content']."<br>";
if($info['reply']!=""){
echo"<b>管理员回复:</br>".$info['reply']."<br>";
}
echo"<hr>";
}
echo"</table>";
}
mysql_close($id);
?>
</td></tr>
<tr><td height=60 bgcolor=#6c6c6c align=center>
<font color=#FFFFFF>版权所有:我的工作室<br>E-mail:[email protected]
</td></tr>
</table>
</body>
</html>
二、login.php页面:
<?php
$name=$_POST["name"];
//如果用户提交了登录信息,则连接到数据库,与数据库中的信息相比较
if ($name!=""){
$password=$_POST["password"];
$id=mysql_connect("localhost","root","luxinluck123");
mysql_select_db("gbook",$id);
$query="select * from admin where username='$name'";
$result=mysql_query($query,$id);
if(mysql_num_rows($result)<1){
echo "该用户不存在!请重新登录!";
}else{
$info=mysql_fetch_array($result,MYSQL_ASSOC);
if ($info['userpass']!=$password){
echo "密码输入错误!请重新登录!";
}else{
//如果用户名密码都正确,则注册一个session来标记其登陆状态。
session_start();
$_SESSION["login"]="YES";
echo "<script language=javascript>alert('登录成功!');location.href=
'manage.php';</script>";
exit;
}
}
mysql_close($id);
}
?>
<html>
<head>
<title>欢迎使用简约不简单-我的留言本 </title>
</head>
<body>
<table border=1 cellspacing=0 cellspadding=0
style="border-collapse:collapse" align=center width=400 bordercolor=black height="358">
<tr><td height=100 bgcolor=#6c6c6c>
<font style="font-size:30px" color=#ffffff face="黑体">简约不简单-我的留言本
</font>
</td>
<tr><td height=25>
<a href=send.php>[我要写留言]</a> <a href=login.php>
[管理留言]</a>
</td></tr>
<tr><td height=178>
<form method="POST" action="login.php">
<table border="1" width="95%" id="table1" cellspacing="0" cellpadding="0"
bordercolor="#808080" style="border-collapse:collapse" height="154">
<tr>
<td colspan="2" height="29">
<p align="center">欢迎管理员登录
</td>
</tr>
<tr>
<td width="32%">
<p align="right">用户名
</td>
<td width="67%"><input type="text" name="name" size="20"></td>
</tr>
<tr>
<td width="32%">
<p align="right">密 码
</td>
<td width="67%"><input type="password" name="password"
size="20"></td>
</tr>
<tr>
<td width="99%" colspan="2">
<p align="center"><input type="submit" value="登录" name="B1"></p>
</td>
</tr>
</table>
</form>
</td></tr>
<tr><td height=58 bgcolor=#6c6c6c align=center>
<font color=#ffffff>版权所有:我的工作室<br>e-mile:[email protected]
</td></tr>
</table>
</body>
</html>
三、send。PHP页面:
<?php
$name=$_POST["name"];
if($name!=""){
$content=$_POST["content"];
$addtime=date("Y-m-d h:i:s");
$id=mysql_connect("localhost","root","luxinluck123");
mysql_select_db("gbook",$id);
$query="insert into message(author,addtime,content,reply)values('$name' ,'$addtime' ,'$content' ,'')";
mysql_query($query,$id);
mysql_close($id);
echo "<script language=javascript> alert('留言成功!单击确定查看留言。');location.herf='index.php';</script>";
exit;
}
?>
<html>
<head>
<title>欢迎使用简约不简单-我的留言本
</title>
</head>
<body>
<table border=1 cellspacing=0 cellpadding=0 style="border-collapse:collapse" align=center width=400 bordercolor=black>
<tr><td height=100 bgcolor=#6c6c6c>
<font style="font-size:30px" color=#ffffff face="黑体">简约不简单-我的原创留言本</font>
</td>
<tr><td height=25>
<a href=send.php>[我要写留言]</a> <a href=login.php>[管理留言]</a>
</td></tr>
<tr><td height=200>
<form method="post" action="send.php">
<table border="1" width="95%" id="table1" cellspacing="0" cellpadding="0" bordercolor="#808080" style="border-collapse:collapse" height="265">
<tr>
<td colspan="2" height="29">
<p align="center">欢迎您填写留言</td>
</tr>
<tr>
<td width="32%">
<p align="right">您的名字</td>
<td width="67%">
<input type="text" name="name" size="20"></td>
</tr>
<tr>
<td width="32%">
<p align="right">留言内容</td>
<td width="67">
<textarea rows="10" name="content" cols="31"></textarea></td>
</tr>
<tr>
<td width="99" colspan="2">
<p align="center"><input type="submit" value="提交" name ="B1"></p>
</td>
</tr>
</table>
</form>
</td></tr>
<tr><td height=80 bgcolor=#6c6c6c align=center>
<font color=#FFFFFF>版权所有:我的工作室<br>E-mail:[email protected]</td></tr>
</table>
</body>
</html>
页面可以运行,但是无法进行登录和留言!纠结死啦
总共六个页面,大为高手看看是不是哪里有问题啊!
一、index.php页面:
<html>
<head>
<title>欢迎使用简约不简单-我的留言本</title>
<style type=text/css>
td{
font-size:12px;
line-height:150%;
}
</style>
</head>
<body>
<table border=1 cellspacing=0 cellspadding=0
style="border-collapse:collapse" align=center width=400 bordercolor=black height="382">
<tr><td height=100 bgcolor=#6c6c6c style="font-size:30px;line-height:30px">
<font color=#ffffff face="黑体">简约不简单-我的留言本</font>
</td><tr>
<tr><td height=25>
<a href=send.php>[我要写留言]</a> <a href=login.php>[管理留言]</a>
</td></tr>
<tr><td height=200>
<?php
$id=mysql_connect("localhost","root","luxinluck123");
mysql_select_db("gbook",$id);
$query="select * from message ";
$result=mysql_query($query,$id);
if(mysql_num_rows($result)<1){
echo " 目前数据表中还没有任何留言!";
}else{
$totalnum=mysql_num_rows($result);
$pagesize=10;
$page=$_GET["page"];
if($page==""){
$page=1;
}
$begin=($page-1)* pagesize;
$totalpage=ceil($totalnum/$pagesize);
echo"<table border=0 width=95%><tr><td>";
$datanum=mysql_num_rows($result);
echo "共有留言".$totalnum."条。";
echo "每页".$pagesize."条,共".$totalpage."页<br>";
for($j=1;$j<=$totalpage;$j++){
echo "<a href=index.php?page=".$j.">[".$j."] </a>";
}
echo "<br>";
$query="SELECT * FROM message order by addtime desc limit
$begin,$pagesize";
$result=mysql_query($query,$id);
for($i=1;$i<$datanum;$i++){
$info=mysql_fetch_array($result,MYSQL_ASSOC);
echo"->[".$info['author']."]于".$info['addtime']."说:<br>";
echo" ".$info['content']."<br>";
if($info['reply']!=""){
echo"<b>管理员回复:</br>".$info['reply']."<br>";
}
echo"<hr>";
}
echo"</table>";
}
mysql_close($id);
?>
</td></tr>
<tr><td height=60 bgcolor=#6c6c6c align=center>
<font color=#FFFFFF>版权所有:我的工作室<br>E-mail:[email protected]
</td></tr>
</table>
</body>
</html>
二、login.php页面:
<?php
$name=$_POST["name"];
//如果用户提交了登录信息,则连接到数据库,与数据库中的信息相比较
if ($name!=""){
$password=$_POST["password"];
$id=mysql_connect("localhost","root","luxinluck123");
mysql_select_db("gbook",$id);
$query="select * from admin where username='$name'";
$result=mysql_query($query,$id);
if(mysql_num_rows($result)<1){
echo "该用户不存在!请重新登录!";
}else{
$info=mysql_fetch_array($result,MYSQL_ASSOC);
if ($info['userpass']!=$password){
echo "密码输入错误!请重新登录!";
}else{
//如果用户名密码都正确,则注册一个session来标记其登陆状态。
session_start();
$_SESSION["login"]="YES";
echo "<script language=javascript>alert('登录成功!');location.href=
'manage.php';</script>";
exit;
}
}
mysql_close($id);
}
?>
<html>
<head>
<title>欢迎使用简约不简单-我的留言本 </title>
</head>
<body>
<table border=1 cellspacing=0 cellspadding=0
style="border-collapse:collapse" align=center width=400 bordercolor=black height="358">
<tr><td height=100 bgcolor=#6c6c6c>
<font style="font-size:30px" color=#ffffff face="黑体">简约不简单-我的留言本
</font>
</td>
<tr><td height=25>
<a href=send.php>[我要写留言]</a> <a href=login.php>
[管理留言]</a>
</td></tr>
<tr><td height=178>
<form method="POST" action="login.php">
<table border="1" width="95%" id="table1" cellspacing="0" cellpadding="0"
bordercolor="#808080" style="border-collapse:collapse" height="154">
<tr>
<td colspan="2" height="29">
<p align="center">欢迎管理员登录
</td>
</tr>
<tr>
<td width="32%">
<p align="right">用户名
</td>
<td width="67%"><input type="text" name="name" size="20"></td>
</tr>
<tr>
<td width="32%">
<p align="right">密 码
</td>
<td width="67%"><input type="password" name="password"
size="20"></td>
</tr>
<tr>
<td width="99%" colspan="2">
<p align="center"><input type="submit" value="登录" name="B1"></p>
</td>
</tr>
</table>
</form>
</td></tr>
<tr><td height=58 bgcolor=#6c6c6c align=center>
<font color=#ffffff>版权所有:我的工作室<br>e-mile:[email protected]
</td></tr>
</table>
</body>
</html>
三、send。PHP页面:
<?php
$name=$_POST["name"];
if($name!=""){
$content=$_POST["content"];
$addtime=date("Y-m-d h:i:s");
$id=mysql_connect("localhost","root","luxinluck123");
mysql_select_db("gbook",$id);
$query="insert into message(author,addtime,content,reply)values('$name' ,'$addtime' ,'$content' ,'')";
mysql_query($query,$id);
mysql_close($id);
echo "<script language=javascript> alert('留言成功!单击确定查看留言。');location.herf='index.php';</script>";
exit;
}
?>
<html>
<head>
<title>欢迎使用简约不简单-我的留言本
</title>
</head>
<body>
<table border=1 cellspacing=0 cellpadding=0 style="border-collapse:collapse" align=center width=400 bordercolor=black>
<tr><td height=100 bgcolor=#6c6c6c>
<font style="font-size:30px" color=#ffffff face="黑体">简约不简单-我的原创留言本</font>
</td>
<tr><td height=25>
<a href=send.php>[我要写留言]</a> <a href=login.php>[管理留言]</a>
</td></tr>
<tr><td height=200>
<form method="post" action="send.php">
<table border="1" width="95%" id="table1" cellspacing="0" cellpadding="0" bordercolor="#808080" style="border-collapse:collapse" height="265">
<tr>
<td colspan="2" height="29">
<p align="center">欢迎您填写留言</td>
</tr>
<tr>
<td width="32%">
<p align="right">您的名字</td>
<td width="67%">
<input type="text" name="name" size="20"></td>
</tr>
<tr>
<td width="32%">
<p align="right">留言内容</td>
<td width="67">
<textarea rows="10" name="content" cols="31"></textarea></td>
</tr>
<tr>
<td width="99" colspan="2">
<p align="center"><input type="submit" value="提交" name ="B1"></p>
</td>
</tr>
</table>
</form>
</td></tr>
<tr><td height=80 bgcolor=#6c6c6c align=center>
<font color=#FFFFFF>版权所有:我的工作室<br>E-mail:[email protected]</td></tr>
</table>
</body>
</html>
这些输出信息是否 有响应 alert('留言成功!单击确定查看留言。');
如果没有响应则说明,在此之前的语句就有错误!另外
$query="select * from admin where username='$name'";
$result=mysql_query($query,$id);
if(mysql_num_rows($result)<1){
echo "该用户不存在!请重新登录!";
}else{
$info=mysql_fetch_array($result,MYSQL_ASSOC);
if ($info['userpass']!=$password){
echo "密码输入错误!请重新登录!";
}else我觉得有点啰嗦了! 直接 select count(usernmae) from admin where username='$name' and userpass=$password
也不用提示得这么明显说 用户名不存在,密码错误这些。这里的作用之后告诉别人什么东西错了,而造成
代码的繁重,影响了执行效率!
1。manage.php
<?php
//首先判断用户是否已经登陆。因为只有登陆用户才能访问此页面。
session_start();
if($_SESSION["login"]!="YES"){
echo "您还没有登陆,无法管理留言!";
exit;
}
//如果用户提交了删除留言的ID,则删除此留言
$delid=$_GET["delid"];
if($delid!=""){
$id=mysql_connect("localhost","root","1234");
mysql_select_db("gbook",$id);
mysql_query("delete from message where id=".$delid);
echo "<script language=javascript>alert('删除成功!');</script>";
mysql_close($id);
}
?>
<HTML>
<HEAD>
<TITLE>欢迎使用简约不简单-我的留言本</TITLE>
<style type=text/css>
TD{
font-size:12px;
line-height:150%;
}
</style>
</HEAD>
<BODY>
<table border=1 cellspacing=0 cellspadding=0
style="border-collapse:collapse" align=center width=400 bordercolor=black height="382">
<tr><td height=100 bgcolor=#6c6c6c
style="font-size:30px;line-height:30px">
<font color=#ffffff face="黑体">简约不简单-我的留言本</font>
</td>
<tr><td height=25>
<a href=logout.php>[注销登陆]</a>
</td></tr>
<tr><td height=200>
<?php
//数据查询、分页、输出部分与index.php基本相同
$id=mysql_connect("localhost","root","luxinluck123");
mysql_select_db("gbook",$id);
$query="select * from message";
$result=mysql_query($query,$id);
if(mysql_num_rows($result)<1){
echo" ,目前数据表中还没有任何留言!";
}else{ //ELSE 开始
$totalnum=mysql_num_rows($result);
$page=$_GET["page"];
if($page==""){
$page=1;
}
$begin=($page-1) * $pagesize;
$totalpage=ceil($totalnum/$pagesize);
echo"<table border=0 width=95%><tr><td>";
$datanum=mysql_num_rows($result);
echo "共同留言".$totalnum."条。";
echo "每页".$pagesize."条,共".$totalpage."页<br>";
for($j=1;$j<=$totalpage;$j++){
echo "<a href=manage.php?page=".$j.">[".$j."] </a>";
}
echo "<br>";$query="SELECT*FROM message order by addtime desc limit $begin,$pagesize";
$result=mysql_query($query,$id);
for($i=1;$i<=$datanum;$i++){
$info=mysql_fetch_array($result,MySQL_ASSOC);
echo "->[".$info['author']."]于".$info['addtime']."说:<br>";
echo " ".$info['content']."<br>";
if($info['reply']!=""){
echo "<b>管理员回复:</b>".$info['reply']."<br>";
}
//此处增加了删除和回复功能
echo"[<a href=manage.php?delid=".$info['id'].">删除此留言</a>]
[<a href=reply.php?id=".$info['id'].">回复留言</a>]";
echo"<hr>";
}
echo"</table>";
} // ELSE 结束
mysql_close($id);
?>
</td><tr>
<tr><td height=60 bgcolor=#6c6c6c align=center>
<font color=#FFFFFF>版权所有:我的工作室<br>E-mail:[email protected]
</td><tr>
</table>
</body>
</html>
2.reply.php
<?php
session_start();
if($_SESSION["login"]!="YES"){
echo "您还没有登陆,无法管理留言!";
exit;
}
$msgid=$_GET["id"];
$reply=$_POST["reply"];
//如果提交了回复,则打开数据库,将留言的reply字段值设置为回复内容
if($reply!=""){
$id=mysql_connect("localhost","root","luxinluck123");
mysql_select_db("gbook",$id);
$query="update message set reply='$reply' where id=".$msgid;
mysql_query($query,$id);
echo "<script language=javascript>alert('回复成功!'); location.href='manage.php';</script>";
exit;
mysql_close($id);
}
$id=mysql_connect("localhost","root","luxinluck123");
mysql_select_db("gbook",$id);
$query="select * from message where id=$msgid";
$result=mysql_query($query,$id);
if(mysql_num_rows($result)<1){
echo "没有此留言";
exit;
}
$msg=mysql_fetch_array($result,MySQL_ASSOC);
?>
<HTML>
<HEAD>
<TITLE>欢迎使用简约不简单-我的留言本</TITLE>
</HEAD>
<BODY>
<table border=1 cellspacing=0 cellspadding=0
style="border-collapse:collapse" align=center width=400 bordercolor=black height="358">
<tr><td height=100 bgcolor=#6c6c6c>
<font style="font-size:30px" color=#ffffff face="黑体">简约不简单-我的留言本</font>
</td>
<tr><td height=25>
<a href="manage.php">[返回管理]</a>
</td></tr>
<tr><td height=178>
<from method="POST" action="reply.php?id=<?php echo $msgid;?>">
<table border="1" width="95%" id="table1" cellspacing="0" cellpadding="0" bordercolor="#808080" style="bode-collapse:collapse" height="154">
<tr>
<td colspan="2" height="29">
<p align="center">管理员回复留言</td>
</tr>
<tr>
<td width="32%">
<p align="right">留言ID</td>
<td width="67%"><?php echo $msg['id'];?></td>
</tr>
<tr>
<td width="32%">
<p align="right">留言人</td>
<td width="67%"><?php echo $msg['author'];?></td>
</tr>
<tr>
<td width="32%">
<p align="right">留言时间</td>
<td width="67%"><?php echo $msg['addtime'];?></td>
</tr>
<tr>
<td width="32%">
<p align="right">留言内容</td>
<td width="67%"><?php echo $msg['content'];?></td>
</tr>
<tr>
<td width="32%">
<p align="right">请输入回复</td>
<td width="67%"><textarea rows="7" name="reply"
cols="33"></textarea></td>
</tr>
<tr>
<td width="99%" colspan="2">
<p align="center"><input type="submit" value="确定" name="B1"></p>
</td>
</tr>
</table>
</form>
</td></tr>
<tr><td height=58 bgcolor=#6c6c6c align=center>
<font color=#FFFFFFF>版权所有:我的工作室<br>E-mail:[email protected]
</td></tr>
</table>
</body>
</html>
<?php mysql_close();?>
3.logout.php
<?php
session_start();
$_SESSION["login"]="";
echo"已成功退出。[<a href=index.php>回首页</a>]";
exit;
?>
麻烦开下,为什么不能登录留言呢!
在send.php页面留言时有提示信息“留言成功!单击确定查看留言”可是并没有自动转向index页面啊!
为什么?