日期:2014-05-17  浏览次数:20855 次

帮忙看看这代码哪里写错了
<!--#include file="../Connections/conn.asp" -->
<!--#include file="../other/md5.Asp" -->
<%
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = MM_conn_STRING
rs.Source = "SELECT * FROM userinfo"
username=request.form("username")
pwd=request.form("pwd")
pwd3=request.form("pwd3")
email=request.form("email")
tel=request.form("tel")
qq=request.form("qq")
if username="" then 
response.Write("<script language=javascript>alert('用户不能为空!');history.go(-1)</script>") 
response.end 
end if

if pwd="" then 
response.Write("<script language=javascript>alert('用户密码不能为空!');history.go(-1)</script>") 
response.end 
end if

if email="" then 
response.Write("<script language=javascript>alert('电子邮箱不能为空!');history.go(-1)</script>") 
response.end 
end if

if request.Form("pwd")<>request.Form("pwd3") then 
Response.Write "<script>alert('密码输入不一致!请重新输入!');history.go(-1);</script>" 
response.end
end if
rs.addnew
rs("username")=username
rs("pwd")=md5(request.form("pwd"))
rs("email")=email
rs("tel")=tel
rs("qq")=qq
rs.update
Response.Write "<script>alert('恭喜您注册成功!');window.location.href='../index.asp';</script>" 
%>

------解决方案--------------------
rs.ActiveConnection = MM_conn_STRING
rs.Source = "SELECT * FROM userinfo"
...


后面没有rs.Open
没有打开rs,后面调用rs.addnew应该会有问题
------解决方案--------------------
rs.Source = "SELECT * FROM userinfo"

后面没有 open

另外,这种编程方式不好,为了添加一条记录,把所有记录都读出来干嘛?
要是有一千万个用户,查数据库得查半天呢.

最好是直接用 insert 语句插入.
如果一宁要用rs,可以读一个空记录来处理.

SELECT * FROM userinfo where 1=0