asp中如何处理重复提交的问题
<!--#includefile="conn.inc"--><%ifSession("userlevel")<>1thenResponse.Redirect"error....
<!--#include file="conn.inc"-->
<%if Session("userlevel")<>1 then
Response.Redirect "error.htm"
end if
if Request("action")=1 then
gonghao=Trim(Request.form("gonghao"))
name=Trim(Request.form("name"))
phone=Trim(Request.form("phone"))
if (IsNull(gonghao) or IsNull(name) or IsNull(phone)) then
Response.write "<script language=javascript>alert('请输入完整的信息!')</script>"
else
rs.open "system",conn, 1, 2
rs.addnew
rs("gonghao")=gonghao
rs("name")=name
rs("phone")=phone
rs.update
Response.write "<script language=javascript>alert('添加成功!')</script>"
end if
end if
set rs=Nothing
set conn=Nothing
%>
<HTML>
<HEAD>
<TITLE>Register</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<STYLE type=text/css>
td { font-family: "宋体"; font-size: 9pt}
body { font-family: "宋体"; font-size: 11pt; line-height: 15pt}
.title { font-family: "宋体"; font-size: 11pt}
A {text-decoration: none; font-family: "宋体"}
A:hover {text-decoration: underline; color: #FF0000; font-family: "宋体"}
</style>
</HEAD>
<BODY bgcolor="#EEEEFF" >
<div align=center>
<TABLE border="1" width="262">
<FORM action="add.asp?action=1" method="POST" name="register" >
<TR><TD align="center" class="title" width="252">
<font color=red><b>添加新记录</b></font>
</TD></TR>
<TR><TD width="252">
工 号: <INPUT type="text" name="gonghao" maxlength="5" size="5">
</TD></TR>
<TR><TD width="252">
姓 名: <INPUT type="text" name="name" maxlength="10" >
</TD></TR>
<TR><TD width="252">
手机号: <INPUT type="text" name="phone" maxlength="11" size="11">
请输入11位手机号
</TD></TR>
<TR><TD align="center" width="252">
<INPUT type="submit" value="确认" name=submit1>
<INPUT type="button" value="关闭窗口" name=button1 onclick="window.close();">
</TD></TR>
</TABLE>
</div>
</FORM>
</BODY>
</HTML>
我添加的时候可以添加一样的工号
怎么办啊
Conn.execute(sql)
Set rs= Server.CreateObject("ADODB.Recordset")
sql="SELECT count(*) FROM system where gonghao='" & request.form("gonghao") & "'"
rs.open "system",Conn,1,2
if rsClass1(0) then
insert
else
Response.write "<script language=javascript>alert('已存在!')</script>"
end if
rs.close
set rs=nothing
Conn.close
Set Conn=Nothing
老师让我插进去
但还是不行
但现在提交不一样的也存在了
郁闷~~~~~~~~~~ 展开
<%if Session("userlevel")<>1 then
Response.Redirect "error.htm"
end if
if Request("action")=1 then
gonghao=Trim(Request.form("gonghao"))
name=Trim(Request.form("name"))
phone=Trim(Request.form("phone"))
if (IsNull(gonghao) or IsNull(name) or IsNull(phone)) then
Response.write "<script language=javascript>alert('请输入完整的信息!')</script>"
else
rs.open "system",conn, 1, 2
rs.addnew
rs("gonghao")=gonghao
rs("name")=name
rs("phone")=phone
rs.update
Response.write "<script language=javascript>alert('添加成功!')</script>"
end if
end if
set rs=Nothing
set conn=Nothing
%>
<HTML>
<HEAD>
<TITLE>Register</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<STYLE type=text/css>
td { font-family: "宋体"; font-size: 9pt}
body { font-family: "宋体"; font-size: 11pt; line-height: 15pt}
.title { font-family: "宋体"; font-size: 11pt}
A {text-decoration: none; font-family: "宋体"}
A:hover {text-decoration: underline; color: #FF0000; font-family: "宋体"}
</style>
</HEAD>
<BODY bgcolor="#EEEEFF" >
<div align=center>
<TABLE border="1" width="262">
<FORM action="add.asp?action=1" method="POST" name="register" >
<TR><TD align="center" class="title" width="252">
<font color=red><b>添加新记录</b></font>
</TD></TR>
<TR><TD width="252">
工 号: <INPUT type="text" name="gonghao" maxlength="5" size="5">
</TD></TR>
<TR><TD width="252">
姓 名: <INPUT type="text" name="name" maxlength="10" >
</TD></TR>
<TR><TD width="252">
手机号: <INPUT type="text" name="phone" maxlength="11" size="11">
请输入11位手机号
</TD></TR>
<TR><TD align="center" width="252">
<INPUT type="submit" value="确认" name=submit1>
<INPUT type="button" value="关闭窗口" name=button1 onclick="window.close();">
</TD></TR>
</TABLE>
</div>
</FORM>
</BODY>
</HTML>
我添加的时候可以添加一样的工号
怎么办啊
Conn.execute(sql)
Set rs= Server.CreateObject("ADODB.Recordset")
sql="SELECT count(*) FROM system where gonghao='" & request.form("gonghao") & "'"
rs.open "system",Conn,1,2
if rsClass1(0) then
insert
else
Response.write "<script language=javascript>alert('已存在!')</script>"
end if
rs.close
set rs=nothing
Conn.close
Set Conn=Nothing
老师让我插进去
但还是不行
但现在提交不一样的也存在了
郁闷~~~~~~~~~~ 展开
1个回答
展开全部
这种情况不叫网页设计上的“重复提交”!
这应该是如何防止有重复工号的问题。
gonghao=Trim(Request.form("gonghao"))
下面加上一个验证查询,可以解决。
set gh=conn.execute("select id from 表 gonghao='"&gonghao&"'")
if not gh.eof then
'提示出错信息:该工号已存在。不能提交
end fi
set gh=nothing
---------------------------------------------
Set rs= Server.CreateObject("ADODB.Recordset")
sql="SELECT count(*) FROM system where gonghao='" & request.form("gonghao") & "'"
rs.open sql,Conn,1,2
if not rs.eof then
Response.write "<script language=javascript>alert('已存在!')</script>"
response.end '加上这句
end if
这应该是如何防止有重复工号的问题。
gonghao=Trim(Request.form("gonghao"))
下面加上一个验证查询,可以解决。
set gh=conn.execute("select id from 表 gonghao='"&gonghao&"'")
if not gh.eof then
'提示出错信息:该工号已存在。不能提交
end fi
set gh=nothing
---------------------------------------------
Set rs= Server.CreateObject("ADODB.Recordset")
sql="SELECT count(*) FROM system where gonghao='" & request.form("gonghao") & "'"
rs.open sql,Conn,1,2
if not rs.eof then
Response.write "<script language=javascript>alert('已存在!')</script>"
response.end '加上这句
end if
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询