ASP程序报错,不知原因,请高手指教!!!
我想实现一个程序,是注册处理页面,当注册成功实显示“注册成功”,失败时显示“这册失败”这几个字,但不知咋的,不管注册是否成功他都显示“注册失败”,我想可能是最后面的判断语句有错,但不知错到哪里,请高手指教!
赋程序:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- #include file="db.inc.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>注册结果</title>
<style type="text/css">
<!--
.style1 {
font-family: "华文行楷";
font-size: 36px;
color: #FF0000;
}
.style2 {color: #FF00FF}
-->
</style>
</head>
<body>
<% on error resume next '如果发生了错误,就跳过发生错误的代码,继续向下运行%>
<table width="768" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<% set rst=server.CreateObject("ADODB.recordset")
rst.open "select * from user where u_user='"&request.form("f_user")&"'",conn,1,1
'在user表中选择出与user表中u_user值相同的数据
if rst.recordcount>0 then
'如果存在这个用户名,对用户进行提示
response.Write "用户名:"&request.Form("f_user")&"已经被占用!请点击后退按钮返回上一页!"
rst.close
set rst=nothing
conn.close
set conn=nothing
response.end
else
'如果不存在这个用户名,则写入数据
rst.close'关闭这个recordset对象
conn.begintrans
rst.open "user",conn,1,3
rst.addnew '插入数据到user表
rst("u_user")=request.form("f_user")
rst("u_code")=request.form("f_code")
rst.update
rst.close
'获取刚才插入数据的自动编号字段,即u_id字段的值
set rst1=conn.execute("select @@identity as uid")
uid=rst1("uid")
set myErrors=conn.errors'把conn对象的errors集合赋值给变量myErrors
rst.open "info",conn,1,3
rst.addnew'插入数据到info表
rst("i_uid")=uid
rst("i_name")=request.form("f_name")
rst("i_sex")=request.form("f_sex")
rst("i_age")=request.form("i_age")
rst("i_vip")=false
rst.update
rst.close
end if
if myErrors.number<>0 then
conn.rollbacktrans
response.Write("注册失败")
else
conn.committrans
response.Write("注册成功")
end if
myErrors.clear
%>
</table>
<%
set rst=nothing
conn.close
set conn=nothing
%>
</body>
</html>
参考答案:我看了后,我觉得应该是你再用SQL语句的时候用的游标参数不对,你吧:
rst.open "select * from user where u_user='"&request.form("f_user")&"'",conn,1,1 改成:
rst.open "select * from user where u_user='"&request.form("f_user")&"'",conn,1,3
如果你还用1的话,那你就不应该用到 rst.update
首先说的是第一个参数1,表示的是使用keyset类型的(这里就是说明游标类型)
第二个参数3表示,游标的锁定类型