php表单重复提交问题

留言本代码:
<!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=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
.STYLE1 {font-size: 12pt}
.STYLE2 {color: #0099FF}
-->
</style>
<script language="javascript">
function jc()
{
var a = document.form1.text.value
if (document.form1.text.value=="")
{
alert("请您填写您的意见和建议!!!");
return false;
}
}
</script>
</head>
<body>
<div align="center">
<form id="form1" name="form1" method="post" action="put.php"onsubmit="return jc();">
<p> </p>
<p> </p>
<table width="300" height="168" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="39" bgcolor="#ECFFD7"><div align="center" class="STYLE1 STYLE2">用户留言本</div></td>
</tr>
<tr>
<td height="83"><div align="center">
<label>
<textarea name="text" cols="40" rows="7" id="text"></textarea>
</label>
</div></td>
</tr>
<tr>
<td height="35"><div align="center">
<label>
<input type="submit" name="Submit" value="提交" />
</label>
</div></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</form>
</div>
</body>
</html>
put.php处理代码:
<?

$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "1234";
$mysql_database = "book";

$sql = "INSERT INTO `ebook` ( `id` , `text` , `time` )
VALUES (
'', '$text', NOW( )
);
";

$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
$id = mysql_insert_id();
mysql_close($conn);
?>
提交成功写入数据库后,弹出提交成功消息框,然后转到 cg.php页面,用户点后退按钮网页失效,防止重复提交,帮我写在上面的代码中,我是php初学者,谢谢!

把你的put.php倒数第4行($result = mysql_query($sql);)修改如下即可:

$result = mysql_query("select count(*) from ebook where text='$text'");
if ($result) {
list($cnt)=mysql_fetch_row($result);
mysql_free_result($result);
} $cnt=0;
if ($cnt>0) echo '该内容已经提交过,不能重复提交!';
else $result = mysql_query($sql);
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-10-20
防止重复提交:
把提交按钮变成disabled.
没有你说的后退网页失效.
第2个回答  2009-10-20
不妨考虑一下使用ajax技术,还有你那段put.php中的代码好像不对吧?php中没有now()吧?
第3个回答  2009-10-23
弹出对话框转到Cg.php页面就行了,不要那么麻烦!
echo("<script type='text/javascript'> alert('成功!');location.href=cg.php';</script>");

给分吧。。。。。。。。。。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网