留言本代码:
<!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初学者,谢谢!
$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);
把提交按钮变成disabled.
没有你说的后退网页失效.
echo("<script type='text/javascript'> alert('成功!');location.href=cg.php';</script>");
给分吧。。。。。。。。。。