如何实现表中比对避免重复提交
各位老师,本人菜鸟一个,拿网上的源码学习,有想法却不知道如何实现,实在搞不懂,现在请教老师们帮助。有一个表list ,我想添加的时候避免重复提交,就是adddate(提交时间)和selpayer(订餐类型)两个字段与表单输入的做比较,如果表中有记录,就提示“记录已添加,否则就执行添加操作。
下面是添加源码。
InOut = Request("add")
If Request.form("add")=" 添 加 " Then
adddate = Request.Form("adddate")
selpayer = Request.Form("selpayer")
seltype = Request.Form("seltype")
moneys = Trim(Request.Form("moneys"))
pjna = Trim(Request.Form("pjna"))
if seltype="" then
Response.Write "<script>alert('请用管理员帐号添加订餐类型!');location='javascript:history.back(-1)';</SCRIPT>"
Response.End
end if
if not isnumeric(moneys) Then
Response.Write "<script>alert('请输入数字整数!');location='javascript:history.back(-1)'</SCRIPT>"
Response.End
end if
Set rs = Server.CreateObject("ADODB.RecordSet")
Sql = "Select * From
- "
rs.Open Sql,Conn,1,3
rs.addNew
rs("InOut") = InOut
rs("PayTypeID") = seltype
rs("Moneys") = moneys
rs("Project") = checkform(pjna)
rs("addTime") = adddate
rs("data") = adddate
rs("etime") = now()
rs("user") = Request.Cookies("id")
rs.Update
rs.Close
Response.Write "<script>alert('操作成功!');this.location.href='pay.asp';</SCRIPT>"
End if
%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link href="images/css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script>
var ie =navigator.appName=="Microsoft Internet Explorer"?true:false;
function $(objID)
{
return document.getElementById(objID);
}
function CheckForm() {
if (document.form1.adddate.value=="")
{
alert("请选择日期!");
return false;
}
if (document.form1.moneys.value=="")
{
alert("份数不能为空!");
document.form1.moneys.focus();
return false;
}
if (document.form1.pjna.value=="")
{
alert("项目名称不能为空!");
document.form1.pjna.focus();
return false;
}
if (document.form1.seltype.value=="")
{
alert("请选择订餐类型!如果没有请先添加!");
return false;
}
}
</script>
<script type="text/javascript" src="images/time.js"></script>
<table width="100%" border="0" align=center cellpadding="6" cellspacing="0">
<form action="" method=post name=form1 onSubmit="return CheckForm()">
<tr>
<td height=25 colspan=5 align="center" bgcolor="#F9F9F9"><b>
<%If InOut=1 Then
Response.Write "<font color=blue>新增订餐</font>"
Else
Response.Write "<font color=red>添 加 支 出</font>"
End if
%> </b></td>
</tr>
<tr>
<td width="35%" align="right">选择日期:</div></td>
<td colspan="4" ><input name="adddate" type="text" size="20" readonly="readonly" onclick="showcalendar(event, this);" onfocus="showcalendar(event, this);if(this.value=='0000-00-00')this.value=''" /></td>
</tr>
<tr>
<td align="right">就餐类型:</td>
<td colspan="4"><select name="seltype">
<%
set rs=server.createobject("adodb.recordset")
sql="select * from [type] Where InOut="&InOut&""
rs.open sql,conn,1,1
response.write "<option sel=selected value='' name=seltype>请选择</option>"
do while not rs.eof
response.write "<option " & sel & " value='"+CStr(rs("ID"))+"' name=seltype>"+rs("PayType")+"</option>"+chr(13)+chr(10)
rs.movenext
loop
rs.close
%>
</select></td>
</tr>
<tr>
<td align="right">份数:</td>
<td colspan="4" >
<input name="moneys" type="text" size="20" maxlength="10" />
(输入数字整数 如:2)</td>
</tr>
<tr>
<td ><div align="right">项目备注:</div></td>
<td colspan="4" ><input name="pjna" type="text" size="50" maxlength="50" /></td>
</tr>
<tr>
<td colspan="5" align="center" ><input type="submit" name="add" value=" 添 加 " /></td>
</tr>
</form>
</table>
</body>
</html>