为什么我的留言本总是无法留言不成功?
我编好了的PHP+MYSQL留言本,代码无误,在留言的页面签写留言后,留言无法插入到数据库中,签写留言点击提交无任何反应既不出现留言成功也不出现留言失败??
我初学PHP照不同的几本书将书中留言本的原码敲入电脑,照书建立数据库和表,可是都出现上述问题,如用phpmyadmin对MYSQL数据库操作可以成功插入数据,可是一到用PHP代码就是无法实现......这个问题困扰我好几天了,请各位老师指点,如有问的不够清楚的地方望各位老师能指出帮我解决这个问题,谢谢!!
问题点数:20、回复次数:5Top
1 楼surfchen(冲浪)回复于 2005-04-01 23:46:39 得分 0
不给出代码谁知道什么原因??
按你所给出的条件,也只能推断大概是提交表单的HTML代码出错了~~Top
2 楼wangxiaoyu12(网小鱼)回复于 2005-04-02 07:45:09 得分 0
<?
if($action == "дºÃÁË!")
{
if( $name == " " || $msg ==" " )
{
//------------[mark 1]
echo"<html>\n";
echo"<head>\n";
echo"<title>³ö´íÁË</title>\n";
echo"</head>\n";
echo"<body bgcolor=#ffcc99><center>\n";
echo"<h1>出错了</h1>\n";
echo"<p><font color = red>信息不全!昵称和内容是必须填写的!</font></p>\n";
echo"<a href=\"javascript:history.go(-1)\">请重试</a>\n";
echo"</center></body>\n";
echo"</html>\n";
}
else
{
//-----------[mark 2]
$connection = @mysql_connect("localhost","root", "716118wxy") or die("无法连接到数据库!");
@mysql_select_db("guest") or die ( "选择数据库失败!");
$query = "insert into guestbook(name, time, msg, email) ";
$query.="values('$name',NULL,'$msg', 'email')";
$result =@mysql_query( $query, $connnection ) or die ("存入数据库失败!");
mysql_close( $connection ) or die ("关闭数据库失败!");
echo"<html>\n";
echo"<head>\n";
echo"<title>成功了!</title>\n";
echo"</head>\n";
echo"<body bgcolor=#ffcc99><center>\n";
echo"<h1><font color = blue >填写留言成功!</font></h1>\n";
echo"<meta http-equiv=\"Refresh\" content=\"5; url=index.php\">";
echo"<h3>五秒钟后自动返回</h3>\n";
echo"<a href = index.php>立刻返回</a>";
echo"</center></body>\n";
echo"<html>";
}
}
else if( $action == "放弃")// ------------[mark 3]
{
echo"<meta http-equiv=\"refresh\" content=\"0; url =index.php\">";
}
else
{
if( $action == "reply" )
{
//-------------[mark 4]
$connection = @mysql_connect("localhost", "root", "716118wxy") or die ("无法连接到数据库!");
@mysql_select_db("guest") or die("选择数据库失败!");
$query = "select name,msg FROM guestbook ";
$query.="where serial=$serial";
$result = @mysql_query($query, $connection) or die("选择失败!");
$row = mysql_fetch_array( $result );
mysql_close( $connection ) or die (" 关闭数据库失败!");
$text = "\n\n[ÔÚ".$row[name]."的留言中提到\n".$row[msg];
}
//-------------[mark 5]
?>
<html>
<head>
<title>签写留言</title>
</head>
<body bgcolor=#ffcc99>
<center><h1><font color=blue>写留言</font></h1></cente>
<table border=0 cellpadding=10 align=center>
<td>
<form method=POST action="<? echo " $PHP_SELF?action=$action"; ?>">
昵称:<input type =text name="name" maxlength="20"><br>
Email:<input type="text" name=email maxlength="30"><br>
内容:<br>
<textarea name="msg" rows="8" cols="60"><? echo $text; ?></textarea><br>
<input type="submit" name="action" value="写好了!">
<input type=reset value="重写">
<input type=submit name=action value="放弃">
</form>
</td>
</table>
</body>
</html>
<?
}
?>Top
3 楼cokeyang(西北狼)回复于 2005-04-02 10:13:04 得分 20
又是垃圾书海人!
唉!
月经题。。。。。全局变量呀!
我都不知道该怎么说了!Top
4 楼cokeyang(西北狼)回复于 2005-04-02 10:24:17 得分 0
<?
if($_GET['action'] == "")
{
if( $_POST['name'] =="" || $_POST['msg'] =="" )
{
//------------[mark 1]
echo"<html>\n";
echo"<head>\n";
echo"<title>信息不全!昵称和内容是必须填写的!</title>\n";
echo"</head>\n";
echo"<body bgcolor=#ffcc99><center>\n";
echo"<h1>出错了</h1>\n";
echo"<p><font color = red>信息不全!昵称和内容是必须填写的!</font></p>\n";
echo"<a href=\"javascript:history.go(-1)\">请重试</a>\n";
echo"</center></body>\n";
echo"</html>\n";
}
else
{
//-----------[mark 2]
$connection = @mysql_connect("localhost","root", "716118wxy") or die("无法连接到数据库!");
@mysql_select_db("guest") or die ( "选择数据库失败!");
$query = "insert into guestbook(name, time, msg, email) ";
$query.="values({$_POST['name']},{time()},{$_POST['msg']},{$_POST['email']})";
$result =@mysql_query( $query, $connnection ) or die ("存入数据库失败!");
mysql_close($connection ) or die ("关闭数据库失败!");
echo"<html>\n";
echo"<head>\n";
echo"<title>成功了!</title>\n";
echo"</head>\n";
echo"<body bgcolor=#ffcc99><center>\n";
echo"<h1><font color = blue >填写留言成功!</font></h1>\n";
echo"<meta http-equiv=\"Refresh\" content=\"5; url=index.php\">";
echo"<h3>五秒钟后自动返回</h3>\n";
echo"<a href = index.php>立刻返回</a>";
echo"</center></body>\n";
echo"<html>";
}
}
else if( $action == "放弃")// ------------[mark 3]
{
echo"<meta http-equiv=\"refresh\" content=\"0; url =index.php\">";
}
else
{
if( $action == "reply" )
{
//-------------[mark 4]
$connection = @mysql_connect("localhost", "root", "716118wxy") or die ("无法连接到数据库!");
@mysql_select_db("guest") or die("选择数据库失败!");
$query = "select name,msg FROM guestbook ";
$query.="where serial=$serial";
$result = @mysql_query($query, $connection) or die("选择失败!");
$row = mysql_fetch_array( $result );
mysql_close( $connection ) or die (" 关闭数据库失败!");
$text = "\n\n[ÔÚ".$row[name]."的留言中提到\n".$row[msg];
}
//-------------[mark 5]
?>
<html>
<head>
<title>签写留言</title>
</head>
<body bgcolor=#ffcc99>
<center><h1><font color=blue>写留言</font></h1></cente>
<table border=0 cellpadding=10 align=center>
<td>
<form method=POST action="<? echo $PHP_SELF."?action=".$action; ?>">
昵称:<input type =text name="name" maxlength="20"><br>
Email:<input type="text" name="email" maxlength="30"><br>
内容:<br>
<textarea name="msg" rows="8" cols="60"><? echo $text; ?></textarea><br>
<input type="submit" name="action" value="写好了!">
<input type=reset value="重写">
<input type=submit name=action value="放弃">
</form>
</td>
</table>
</body>
</html>
<?
}
?>Top
5 楼wangxiaoyu12(网小鱼)回复于 2005-04-02 16:47:34 得分 0
谢谢您,这问题困扰我好几天了,我还以为是我MYSQL数据库安装时候的问题呢,弄得我这几天郁闷的要死~~~再次感谢您~~~Top




