用ASP实现写入数据库的功能

该博客演示了如何使用ASP来实现用户注册功能,通过检查用户名是否已存在,然后将新用户信息插入到数据库的两个表中。如果注册过程中出现错误,会显示错误信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!-- #include file="db.inc.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>注册结果</title>
<style type="text/css">
<!-
body {
margin-top: 0px;
margin-bottom: 0px;
background-image: url();
background-repeat: no-repeat;
}
.STYLE2 {
 font-size: 50px;
 font-weight: bold;
 color: #FF0000;
}
-->
</style></head>
<body>
<% on error resume next '如果发生了错误,就跳过发生错误的代码,继续向下运行%>

<table width="800" border="0" align="center" cellspacing="0">
<tr>
<td width="218" height="72">&nbsp;</td>
<td width="376">&nbsp;</td>
<td width="200">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center" valign="middle">
<%
'创建recordset对象方法1
set rst=server.CreateObject("adodb.recordset")
rst.open "select * from user where u_user='" & request.form("f_user") & "'",conn,1,1
if rst.recordcount>0 then
'如果存在这个用户名,对用户进行提示
response.write "用户名:" & request.form("f_user") & "已经被占用!请点击后退按钮返回上一页!"
     rst.close
  set rst=nothing
  conn.close
  set rst=nothing
    response.End()
 else
 '如果用户名不存在则写入数据
set rst1=conn.Execute("insert into user (u_user,u_code) values ('" & request.Form("f_user") & "','" & request.form("f_code") & "')")
  rst.close
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")
rst.open "info",conn,1,3
set myerrors=conn.errors
        if myerrors.count>0 then
    for i=0 to myerrors.count-1
      response.Write("错误原因:" & myerrors.item(i).description & "<br>")
    next
  end if
  if err.number<>0 then
response.Write "ERR对象捕获错误:" & err.description
end if
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("f_age")
rst("i_vip")=false
rst.update
rst.close
    if err.number<>0 then
 %>
    <span class="STYLE2">注册失败</span><br>
    <% else %>
    <span class="STYLE2">注册成功</span></td>
    <%
   end if
 end if
 %>
<td>&nbsp;</td>
</tr>
<tr>
<td height="154">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<%
set rst=nothing
conn.close
set conn=nothing
%>
</body>
</html>47/48 shandian
rst.open "select * from user where u_user='" & request.form("f_user") & "'",conn,

#注 user是数据库表名,u_user是表里的某个字段名,request.form("f_user")里的f_user是你页面里的<form></form>里的某个表单名,比如:<input name=f_user type=text>
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值