ASP 表单提交 检查数据

来源:百度知道 编辑:UC知道 时间:2024/04/29 13:06:22
我做了个简单的注册页
名字和QQ都需要写,而且不能重复
请问如何写?
我下面的代码检测文本框是否为空是一起检测的
如何分开检测比如:名字没写提示名字还没写QQ没写提示QQ没写

还有重复注册问题
我现在只写了名字不能重复,如何多增家个QQ也不能重复?
如果行追加分
我的代码:

<%@ language="vbscript" %>
<%
names=trim(server.htmlencode(request.form("names")))
if request.form("names")="" or request.form("qq")=""then%>
<Script>
alert("请输入关键字");
history.back();
</script>

<%
response.end
end if
set conn=server.createobject("ADODB.connection")
conn.open "DBQ=" & server.MapPath("database.mdb") & ";DRIVER={Microsoft Access Driver (*.mdb)}"
set rs=conn.execute("select * from biao where names='" & names & "'")
if not rs.eof then%>
<Script>
alert("关键字已存在");
history.back();
</scrip

不用那么复杂
<%
if request.form("names")="" then
response.write "<script>alert('用户名不得为空!');window.history.go(-1);</script>"
response.end
end if

if request.form("qq")="" then
response.write "<script>alert('oicq不得为空!');window.history.go(-1);</script>"
response.end
end if
%>

set rs=conn.execute("select * from biao where qq='" & qq & "'")
if not rs.eof then%>
<Script>
alert("关键字已存在");
history.back();
</script>
和判断名字一样,去数据库里找,如果有就提示不能重复.数据库qq字段如果设的是数字,set rs=conn.execute("select * from biao where qq=" & qq & "") 就像这样把单引号去掉.