首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

小弟我用ASP写了个注册页面,运行时不报错,但是不能把数据写入数据库

2012-03-11 
我用ASP写了个注册页面,运行时不报错,但是不能把数据写入数据库代码是这样的%@LANGUAGEVBSCRIPT CODEP

我用ASP写了个注册页面,运行时不报错,但是不能把数据写入数据库
代码是这样的

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- #include file="db.inc.asp"-->
<!-- #include file="config/function.inc.asp"-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户注册</title>
<style type="text/css">
#apDiv1 {
width:600px;
height:800px;
z-index:1;
left: 243px;
top: 61px;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
}
body {
margin-top: 0px;
background-color: #FFF;
}
#apDiv2 {
position:absolute;
width:600px;
height:500px;
z-index:1;
background-color: #FFFFFF;
background-image: url(images/regbg.jpg);
}
#apDiv3 {
position:absolute;
width:400px;
height:266px;
z-index:2;
left: 102px;
top: 114px;
background-color: #FFFFFF;
text-align: center;
}

.regtd {
text-align: right;
}
.red {
color: #F00;
}
table{
  border-collapse: collapse;
border: none;
height: 189px;
width: 358px;
}
td 
{
border: 1px solid #000;

.zdq {
text-align: left;
}
</style>
</head>

<body>
<%
on error resume next
dim sql,rst
if request.QueryString("act")="reg" then
  if request.form("f_user")="" or request.form("f_code")="" then
  msgboxU "用户名和密码不能为空!"
  else
  set rst=server.CreateObject("adodb.recordset")
sql="select count(*) as recnum from tbl_user where u_user='"&request.form("f_user")&"'"
  rst.open sql,conn,1,1
if rst("recnum")>0 then 
msgboxU "已存在同名用户!"
else 
sql2="insert into tbl_user(u_user,u_code,u_name,u_sex,u_tel,u_mail) values('"&request.form("f_user")&"','"&request.form("f_code")&"','"&request.form("f_name")&"','"&request.form("f_sex")&"','"&request.form("f_tel")&"','"&request.form("f_tel")&"')"
conn.execute(sql2) 
  set myErr=conn.errors
if myErr=0 then
msgboxU"注册成功"
else 
msgboxU"注册失败! 原因:" & myErr.item(0).description
end if

end if
rst.close
ser.rst=nothing
end if
end if
%>

<div id="apDiv1">
  <div id="apDiv2">
  <div id="apDiv3">
  <form id="form1" name="form" method="post" action="register.asp?act=reg">
  <table> 
  <tr>
  <td colspan="3" class="zdq">请在下面填写注册信息,带<span class="red">*</span>为必填内容</td>
  </tr>
  <tr>
  <td width="103" align="right">用户名:</td>
  <td width="167" class="zdq">
  <input name="f_user" type="text" id="user" size="18" /></td>
  <td width="78" class="zdq"><span class="red">*</span></td>


  </tr>
  <tr>
  <td align="right">密码:</td>
  <td class="zdq" >
  <input name="f_code" type="password" id="password" size="18" /></td>
  <td class="zdq"><span class="red">*</span></td>
  </tr>
   
  <tr>
  <td align="right" >重复密码:</td>
  <td class="zdq">
  <input name="f_recode" type="password" id="password" size="18" /></td>
  <td class="zdq"><span class="red">*</span></td>
  </tr>  
  <tr>
  <td align="right" bgcolor="#FFFFFF">姓名:</td>
  <td class="zdq" >
  <input name="f_name" type="text" id="name" size="18" /> </td>
  <td >&nbsp;</td>
  </tr>
  <tr>
  <td align="right" >性别:</td>
  <td class="zdq">
  <select name="f_sex" id="sex">
  <option value="3" selected="selected"> </option>
  <option value="男">男</option>
  <option value="女">女</option>
  </select></td>
  <td > </td>
  </tr>
  <tr>
  <td align="right" >年龄:</td>
  <td class="zdq">
  <input name="f_age" type="text" id="age" size="5" /></td>
  <td> </td>
  </tr>
  <tr>
  <td align="right">联系电话:</td>
  <td class="zdq">
  <input name="f_tel" type="text" id="textfield" size="15" /></td>
  <td> </td>
  </tr>
  <tr>
  <td align="right">邮箱:</td>
  <td class="zdq">
  <input name="f_email" type="text" id="textfield2" size="15" /></td>
  <td class="red">&nbsp;</td>
  </tr>
  <tr>
  <td align="center" colspan="3"> <input name="submit" type="submit" id="submit" value="提交注册资料" />
  <input type="reset" name="sumbit2" id="sumbit2" value="重置资料" /></td>
  </tr>

  </table>
  </form>
  </div>
  </div>
</div>
<%
conn.close
set conn=nothing
%>
</body>
</html>


[解决办法]
不是应该有个连接数据库的语句吗??怎么直接就select了
[解决办法]


如果默认的你就不必用<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>,再把sql拆开设置,数据库错位往往会出现莫名其妙的问题。
[解决办法]
sql2="insert into tbl_user(u_user,u_code,u_name,u_sex,u_tel,u_mail) values('"&request.form("f_user")&"','"&request.form("f_code")&"','"&request.form("f_name")&"','"&request.form("f_sex")&"','"&request.form("f_tel")&"','"&request.form("f_tel")&"')"

上面这句中有两个request.form("f_tel")。
另外检查一下数据库中字段的宽度够吗?
[解决办法]
字段是否允许控制等?

热点排行