<title>添加数据</title><?php
$table=$_REQUEST["select"];
$leibie=$_REQUEST["select1"];
$title=$_REQUEST["title"];
$comment=$_REQUEST["comment"];
$date=time();
if($title==""||$comment=="")
{
echo "资料不完整,请返回重新填写";
exit();
}
else {
$link=mysql_connect("localhost","root","21508926");
mysql_select_db("meet",$link);
if($table=='about'||$table=='lilun'||$table=='library'||$table=='notice')
{
if ($leibie==3)
{$query="INSERT INTO `$table` (id,title,comment,date,num) values (NULL,'$title','$comment','$date','')";
mysql_query($query,$link);
$result=mysql_query($query,$link);
if($result) {echo "添加成功1";}
else{echo "添加失败1"; echo mysql_error();}
}
else{echo "你的选择有错"; exit();}
}
else {
$query="INSERT INTO mainos (id,title,comment,lwo,date,num) values (NULL,'$title','$comment','$leibie','$date','')";
mysql_query($query,$link);
$result=mysql_query($query,$link);
if($result)
{
echo "添加成功2";
}
else
{
echo "添加失败2";
echo mysql_error();
}
}
}
mysql_close($link);
?>
代码如上.
$table=$_REQUEST["select"];
$leibie=$_REQUEST["select1"];
$title=$_REQUEST["title"];
$comment=$_REQUEST["comment"];
$date=time();
if($title==""||$comment=="")
{
echo "资料不完整,请返回重新填写";
exit();
}
else {
$link=mysql_connect("localhost","root","21508926");
mysql_select_db("meet",$link);
if($table=='about'||$table=='lilun'||$table=='library'||$table=='notice')
{
if ($leibie==3)
{$query="INSERT INTO `$table` (id,title,comment,date,num) values (NULL,'$title','$comment','$date','')";
mysql_query($query,$link);
$result=mysql_query($query,$link);
if($result) {echo "添加成功1";}
else{echo "添加失败1"; echo mysql_error();}
}
else{echo "你的选择有错"; exit();}
}
else {
$query="INSERT INTO mainos (id,title,comment,lwo,date,num) values (NULL,'$title','$comment','$leibie','$date','')";
mysql_query($query,$link);
$result=mysql_query($query,$link);
if($result)
{
echo "添加成功2";
}
else
{
echo "添加失败2";
echo mysql_error();
}
}
}
mysql_close($link);
?>
代码如上.
<?php
$table=$_REQUEST["select"];
$leibie=$_REQUEST["select1"];
$title=$_REQUEST["title"];
$comment=$_REQUEST["comment"];
$date=time();
if($title==""||$comment=="")
{
echo "资料不完整,请返回重新填写";
exit();
}
else {
$link=mysql_connect("localhost","root","21508926");
mysql_select_db("meet",$link);
if($table=='about'||$table=='lilun'||$table=='library'||$table=='notice')
{
if ($leibie==3)
{
$query="INSERT INTO `$table` (id,title,comment,date,num) values (NULL,'$title','$comment','$date','')"; mysql_query($query,$link);
$result=mysql_query($query,$link);
if($result)
{
echo "添加成功1";
}
else
{
echo "添加失败1";
echo mysql_error();
}
}
else
{
echo "你的选择有错"; exit();
}
}
else {
$query="INSERT INTO mainos (id,title,comment,lwo,date,num) values (NULL,'$title','$comment','$leibie','$date','')";
mysql_query($query,$link);
$result=mysql_query($query,$link);
if($result)
{
echo "添加成功2";
}
else
{
echo "添加失败2";
echo mysql_error();
}
}
}
mysql_close($link);
echo "<br>你可以选择<a href=manage.php>继续</a>";
echo "<br>或者<a href=logout.php>注销</a>";
?>
贴了一个清晰一点的代码,大家帮忙看看吧,
还是提交了两次,而且两条记录的提交时间显示的都是一样的,不知道是什么原因.
服务器端解决的办法是
<?
session_start();
if(count($_POST)>0) {
if(!isset($_SESSION['bup']))
$_SESSION['bup'] = "";
if($_SESSION['bup'] != serialize($_POST)) {
$_SESSION['bup'] = serialize($_POST);
// 插入操作
}
// 其他操作
?>
是不是有button 按钮?问题有可能出在这个地方的
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<link href="../main.css" rel="stylesheet" type="text/css">
</head><body><table width="754" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="754" height="36" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="754" height="36" valign="top"><div align="center"><font color="#FF0000">请认真填写以下的内容,你所输入的内容将被录入数据库!<br>
</font>
<hr>
<font color="#FF0000"> </font></div></td>
</tr>
</table></td>
</tr>
<tr>
<td height="267" valign="top">
<form name="form1" method="post" action="add.php">
<p><br>
你要将文章输入
<select name="select" size="1">
<option value="about" selected>关于大会</option>
<option value="lilun">理论研究</option>
<option value="mainos">主流os</option>
<option value="library">资料库</option>
<option value="notice">通知</option>
</select>
数据库<br>
<br>
你的文章类型是
<select name="select1" size="1" id="select1">
<option value="3" selected>不选择</option>
<option value="1">linux</option>
<option value="2">windows</option>
</select>
(如果向主流os栏目里添加文章请选择,其他的数据库添加不用) <br>
<br>
文章标题
<input name="title" type="text" id="title">
<br>
<br>
文章内容
<textarea name="comment" id="comment" rows="15" cols="75"></textarea>
<br>
<br>
<input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit2" value="重置">
</p>
<hr>
</form></td>
</tr>
<tr>
<td height="26" valign="top"><div align="center"><a href="logout.php">注销登陆</a></div></td>
</tr>
<tr>
<td height="42"> </td>
</tr>
</table>
</body>
</html>
这是表单的代码,最上面的php文件是利用cookie判断用户是否注册的。
$result=mysql_query($query,$link);你执行了两遍mysql_query当然是插两条了把第一条注释掉