标题:[求助]如何在表中添加一个新的数据?
只看楼主
mqbb
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2005-6-1
 问题点数:0 回复次数:5 
[求助]如何在表中添加一个新的数据?

这里是源代码,我想在注册页面加上电话号码一栏,我加上去了,可是注册以后不会写进数据库中,各位达人帮我看看哪里出问题了? <!--#include file="common.asp" -->

<% Dim str_db_username 'Holds username in database Dim str_wanted_username 'Holds requested username Dim str_new_usercode 'Holds the newly generate user code Dim int_random_number 'Holds a random number Dim int_random_number_max 'Holds maximum value of random number Dim int_random_number_min 'Holds minimum value of random number Dim str_password 'Holds the password user chose Dim rs_new_user 'Recordsheet for new user Dim rs_check_username 'Recordsheet to check usernames originality Dim str_dh IF request.querystring("step") = 5 THEN

'Set the variables to the forms enetered values str_wanted_username = Request.form("username") str_password = Request.form("pw1") str_dh= Request.form("dh") 'Create new database connection adoCon.Open cString

'Create new SQL string strSQL="SELECT * FROM tbl_authors"

'Create new recordsheet set rs_check_username=server.CreateObject("ADODB.Recordset")

'Open the recordsheet and execute sql rs_check_username.open strSQL,adoCon

'Loop until record ends Do While not rs_check_username.EOF

'Set variable to hold a database username value str_db_username = rs_check_username("name")

'If the variables match then the username is not unique, redirect to error page IF str_db_username = str_wanted_username THEN Response.redirect("error.asp")

'Move to next record rs_check_username.MoveNext

'Loop Loop

'Close n clean! rs_check_username.Close Set rs_check_username = Nothing

'Create a new random number Randomize int_random_number_Min = 1 int_random_number_Max = 999999999 int_random_number = Int(((int_random_number_Max-int_random_number_Min+1) * Rnd) + int_random_number_Min) 'Convert the new number into a string value int_random_number = Cstr(int_random_number)

'Set the variable to hold the users password, username and random number str_new_usercode = str_wanted_username + int_random_number + str_password

'Create a new SQL string strsql="SELECT * FROM tbl_authors"

'Create a new recordsheet set rs_new_user=server.CreateObject("ADODB.Recordset")

'Set correct cursor and locktypes rs_new_user.CursorType = 5 rs_new_user.LockType = 5

'Open recordsheet and execute SQL string rs_new_user.open strsql,adocon

'Set recordsheet to add a new record rs_new_user.AddNew

'Enter a new record into the database rs_new_user.fields("name")= Request.form("username") rs_new_user.fields("email")= Request.form("email") rs_new_user.fields("password")= Request.form("pw1") rs_new_user.fields("dianhua")= Request.form("dh") rs_new_user.fields("code") = str_new_usercode

'Update the recorsheet rs_new_user.update

'Close and clean rs_new_user.close set rs_new_user = nothing adoCon.close

'Redirect user to step 4 response.redirect("welcome.asp")

else end if

%>

<html> <head> <style> td{font-size:9pt;line-height:140%} body{font-size:9pt;line-height:140%}

a:link { color: #0033CC; text-decoration: none } a:visited { color: #0033CC; text-decoration: none } a:active { color: #FF0000; text-decoration: none } a:hover { color: #000000; text-decoration: underline} </style> <SCRIPT LANGUAGE="JavaScript"> <!-- function DoSubmit(obj) { var username = obj.username.value; var password = obj.pw1.value; var confirmation = obj.pw2.value; var email = obj.email.value;

var strMailFilter = /^.+@.+\..{2,3}$/; var strIllegalChars = /[\(\)\<\>\,\;\:\\\/\*\-\+\=\"\[\]]/; var submitform = true; var error = '--------------------- 警 告 ---------------------\n\n'; error += ' 有以下错误发生 : \n\n';

if (username.length < 1) { error += ' + 用户名不能为空! \n'; submitform = false; } if (username.length > 20) { error += ' + 用户名最长为20字母! \n'; submitform = false; } if (password.length < 5) { error += ' + 密码最少设为5位! \n'; submitform = false; } if (password.length > 20) { error += ' + 密码最长为20位! \n'; submitform = false; } if (confirmation.length < 1) { error += ' + 确认密码不能为空 \n'; submitform = false; } if (password != confirmation) { error += ' + 两次密码输入不相同! \n'; submitform = false; } if (email.length > 80) { error += ' + Email最长为80位! \n'; submitform = false; } if (email.length > 1 && email.match(strIllegalChars)) { error += ' + 您的email中带有非法字符! \n'; submitform = false; } if (email.length > 1 && !email.match(strIllegalChars) && !(strMailFilter.test(email))) { error += ' + 您的email地址不存在! \n'; submitform = false; } if (submitform) { obj.submit(); } else { error += '\n--------------------- 警 告 ---------------------\n\n'; alert (error); return false; } } --> </script> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <form action="register.asp?step=2" name="myForm" method="post" onReset="return confirm('Are you sure you wish to reset the form?');"> <td align="center"> <p><BR> 有<font color="#FF0000">*</font>标志的必需填写!<BR> <BR> <BR> <BR> <b> 用户名<font color="#FF0000">*</font> </b> <input type="text" name="username" size="30" maxlength="80" class="textbox"> 请设定您的用户名!<BR> <BR> <BR> <b> 密码<font color="#FF0000">:*</font> </b> <input type="password" name="pw1" size="30" maxlength="80" class="textbox"> 请设定您的密码!</p> <p><BR> <b>重复密码:<font color="#FF0000">*</font> </b> <input type="password" name="pw2" size="30" maxlength="80" class="textbox"> 再次填写刚才的密码! </p> <p><b>联系电话<font color="#FF0000">:*</font> </b> <input type="dianhua" name="dh" size="15" maxlength="15" class="textbox"> 请填写你的联系电话!<BR> <BR> <b> Email:</b> <input type="text" name="email" size="30" maxlength="80" class="textbox"> 您的Email地址!<BR> <BR> <input type="button" value="注册" class="button" onClick="DoSubmit(document.myForm)"> &nbsp; <input type="reset" value="重写" class="button"> <BR> <BR> <BR> <center> <font size="1" color="#000000" face="verdana"></p> </td> </form> </tr> </table>

</body>

</html>

搜索更多相关主题的帖子: 数据 
2005-06-01 18:36
hxfly
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:5807
专家分:108
注 册:2005-4-7
得分:0 
把错误信息贴出来

2005-06-02 08:51
mqbb
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2005-6-1
得分:0 
运行时没有错误信息,只是我打开数据库看里面dianhua那栏里面没有写入任何电话号码.
2005-06-02 11:15
hxfly
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:5807
专家分:108
注 册:2005-4-7
得分:0 
&lt;input type="dianhua" name="dh" size="15" maxlength="15"  class="textbox"&gt;
改成
&lt;input type="text" name="dh" size="15" maxlength="15" &gt;
然后在数据库操作的页面输出一下提交的内容
看看提交的dh的内容是什么
&lt;%=request("dh")%&gt;

2005-06-02 11:34
mqbb
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2005-6-1
得分:0 
好的,我现在不是很急,到时候我可能要找你帮忙,我在网上下了一个注册登记的程序,我想在里面添加一些他原先没有的内容,比如说电话,地址..
我愿以20个Q币作为酬劳..
2005-06-02 13:22
hxfly
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:5807
专家分:108
注 册:2005-4-7
得分:0 
首先感谢你的信任
其次
我是不会接受你的Q币的

在论坛上大家互相帮助很正常
如果你有问题
欢迎你来论坛上问
你经常来这个论坛就是对我最大的支持了
谢谢

也有可能你问我的时候我因为工作的问题没有时间
那样就非常遗憾了
我尽自己最大努力帮你

2005-06-02 13:34



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-19861-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.043848 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved