经典论坛's Archiver

andysaint35 发表于 2008-7-2 18:41

asp 注册问题

<%
dim logintime
t1=request("t1")
t2=request("t2")
t3=request("t3")
t4=request("t4")
t5=request("t5")
logintime=now()
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("login.mdb")
sql="insert into [login]([name],[password],[e-mail],mobilephone,introduce,logintime)values('"&t1&"','"&t2&"','"&t3&"','"&t4&"','"&t5&"','"&logintime&"')"


Set rs = Server.CreateObject("ADODB.Connection")
set rs=conn.execute("select name from [login] where name='"&t1&"'")
set rs=conn.execute("select password from [login] where password='"&t2&"'")
if not rs.eof then %>

<script language="javascript">
alert("对不起,已存在此用户名或密码,请重新注册一个。");
history.go(-1);
</script>

<% else

if t1="" then
%><script>alert("用户帐号必须填写");location.href="regist.html";</script>

<% end if
if t2="" then %>
<script>alert("用户密码必须填写");location.href="regist.html";</script>
<%
end if
sql="insert into [login]([name],[password],[e-mail],mobilephone,introduce,logintime)values

('"&t1&"','"&t2&"','"&t3&"','"&t4&"','"&t5&"','"&logintime&"')"
end if
set rs=conn.execute(sql)

response.Write ("注册成功! 您的帐号是"+t1)
session("t1")=t1

%>
<a href="index.asp"> 请点击这里进入</a>
哪位大哥看看这段该怎么写!!!
这段程序是能运行,但是我的意思是数据在不能与数据库中的数据一样和不能为空的情况下,写入数据库,现在的情况是即使有了提示,但还是写进数据库了

kyllen 发表于 2008-7-3 13:26

你的判断代码和写数据的代码顺序貌似错了。
应该是先进行判断,如果满足条件,再进行写操作。

pjp3279 发表于 2008-7-7 20:25

对头!你应该先进行判断!然后在写入数据库!

wagx 发表于 2008-7-7 20:45

你判断完没有把他强制停止执行。
按你这样的话,,,
[quote]if t1="" then
%><script>alert("用户帐号必须填写");location.href="regist.html";</script>

<% end if
if t2="" then %>
<script>alert("用户密码必须填写");location.href="regist.html";</script>
<%
end if[/quote]这个两个等于白判断,,,只是提示而已,,但还是会执行下面的instr语句,,所以照样会入数据库。
你可以在 end if上面加个response.end让他停止执行页面。

wagx 发表于 2008-7-7 20:49

还有,。。。你这代码写得很乱啊,,呵呵、、
再者,,,最好先判断post/get过来的字符串--》判断用户是否存在--》入数据库

页: [1]



Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.