| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1344 人关注过本帖
标题:求助:输入错误时不能返回注册页面
只看楼主 加入收藏
lyg540612
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-8-12
收藏
 问题点数:0 回复次数:3 
求助:输入错误时不能返回注册页面
源程序为:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.
<!--#include file="../Connections/conn.asp" -->
<%
' *** Edit Operations: declare variables
Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Redirect if username exists
MM_flag="MM_insert"
If (CStr(Request(MM_flag)) <> "") Then
  MM_dupKeyRedirect="registNo.html"
  MM_rsKeyConnection=MM_conn_STRING
  MM_dupKeyUsernameValue = CStr(Request.Form("name"))
  MM_dupKeySQL="SELECT name FROM user WHERE name='" & MM_dupKeyUsernameValue & "'"
  MM_adodbRecordset="ADODB.Recordset"
  set MM_rsKey=Server.CreateObject(MM_adodbRecordset)
  MM_rsKey.ActiveConnection=MM_rsKeyConnection
  MM_rsKey.Source=MM_dupKeySQL
  MM_rsKey.CursorType=0
  MM_rsKey.CursorLocation=2
  MM_rsKey.LockType=3
  MM_rsKey.Open
  If Not MM_rsKey.EOF Or Not MM_rsKey.BOF Then
    ' the username was found - can not add the requested username
    MM_qsChar = "?"
    If (InStr(1,MM_dupKeyRedirect,"?") >= 1) Then MM_qsChar = "&"
    MM_dupKeyRedirect = MM_dupKeyRedirect & MM_qsChar & "requsername=" & MM_dupKeyUsernameValue
    Response.Redirect(MM_dupKeyRedirect)
  End If
  MM_rsKey.Close
End If
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "Form") Then

  MM_editConnection = MM_conn_STRING
  MM_editTable = "user"
  MM_editRedirectUrl = "registOk.html"
  MM_fieldsStr  = "name|value|password|value|sex|value|age|value|born|value|QQ|value|email|value|record|value|question|value|answer|value|msn|value|url|value|content|value"
  MM_columnsStr = "name|',none,''|pwd|',none,''|sex|',none,''|age|none,none,NULL|born|',none,NULL|QQ|none,none,NULL|email|',none,''|record|',none,''|question|',none,''|answer|',none,''|MSN|',none,''|url|',none,''|content|',none,''"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")
  
  ' set the form values
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

  ' create the sql insert statement
  MM_tableValues = ""
  MM_dbValues = ""
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_formVal = MM_fields(MM_i+1)
    MM_typeArray = Split(MM_columns(MM_i+1),",")
    MM_delim = MM_typeArray(0)
    If (MM_delim = "none") Then MM_delim = ""
    MM_altVal = MM_typeArray(1)
    If (MM_altVal = "none") Then MM_altVal = ""
    MM_emptyVal = MM_typeArray(2)
    If (MM_emptyVal = "none") Then MM_emptyVal = ""
    If (MM_formVal = "") Then
      MM_formVal = MM_emptyVal
    Else
      If (MM_altVal <> "") Then
        MM_formVal = MM_altVal
      ElseIf (MM_delim = "'") Then  ' escape quotes
        MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
      Else
        MM_formVal = MM_delim + MM_formVal + MM_delim
      End If
    End If
    If (MM_i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & ","
      MM_dbValues = MM_dbValues & ","
    End If
    MM_tableValues = MM_tableValues & MM_columns(MM_i)
    MM_dbValues = MM_dbValues & MM_formVal
  Next
  MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

  If (Not MM_abortEdit) Then
    ' execute the insert
    Set MM_editCmd = Server.CreateObject(")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_ = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_conn_STRING
Recordset1.Source = "SELECT * FROM user"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用户注册</title>
<style type="text/css">
<!--
.style5 {color: #0000FF}
.style9 {font-size: 9pt; color: #0000FF; }
.style4 {font-family: Arial;
    font-size: 9pt;
    color: #0000FF;
}
.style10 {    color: #FFFFFF;
    font-weight: bold;
    font-size: 14pt;
}
.style37 {font-size: 9pt}
-->
</style>


<script type="text/javascript">
function checkform(fName,obj,minl,maxl,hideCode)
{
    switch(fName)
    {
        case "email"://验证电子邮件
           return(checkEmail(obj,minl,maxl,hideCode));
        break;

        case "name"://验证用户名
            return(checkName(obj,minl,maxl,hideCode));
        break;
        case "password"://验证密码
            return(checkpassword(obj,minl,maxl,hideCode));
        break;
        case "QQ"://验证QQ
            return(checkQQ(obj,minl,maxl,hideCode));
        break;
        case "textlength"://限制字数
            return(checkCodeLength(obj,minl,maxl,hideCode));
        break;
        default:
        alert("程序引用错误,需要的参数只能为:\n1.")
        return;
        break;
    }
}
function checkName(obj,Minl,Maxl,hideCode)
{
    //验证用户名程序,限制只能输入英文或数字
    var objvalue=obj.value;
    if(objvalue.length<Minl||objvalue.length>Maxl)
    {
        alert("用户名长度限于"+Minl+"个和"+Maxl+"个字符之间,请重新输入");
        obj.focus();
        return false;
    }
    var reg=/^\w+$/
    if(!reg.test(objvalue))
    {
        alert("用户名只允许包含数字,英文或下划线");
        obj.focus();
        return false;
    }
}
//if Request.Form("name")="" then
//Response.write "用户名不能为为空"
//end if

function checkpassword(obj,Minl,Maxl,hideCode)
{
    //验证密码程序,限制只能输入英文或数字
    var objvalue=obj.value;
    var iptpassword=document.getElementById("password");
    var iptpassword2=document.getElementById("password2");
    if(iptpassword.value!=iptpassword2.value)
    {
        alert('两次输入的密码不一致');
    }

    if(objvalue.length<Minl||objvalue.length>Maxl)
    {
        alert("密码长度限于"+Minl+"个和"+Maxl+"个字符之间,请重新输入");
        obj.focus();
        return false;
    }
}
function checkEmail(obj,Minl,Maxl,hideCode)
{
    //验证EMAIL程序
    var objvalue=obj.value;
    if(objvalue.length<Minl||objvalue.length>Maxl)
    {
        alert("对不起,电子邮件字符长度不应该小于"+Minl+"或不应该长于"+Maxl+"个字符");
        obj.focus();
        return false;
    }
    var reg=/^\w+@\w+.(\w+.\w+|\w+)$/;
    if(!reg.test(objvalue))
    {
        alert("请正确输入电子邮件地址");
        obj.focus();
        return false;
    }
}
function checkCodeLength(obj,Minl,Maxl,hideCode)
{
    //验证字数程序
    var valueLength=obj.value.length;
    if(valueLength<Minl||valueLength>Maxl)
    {
        alert("对不起,您输入的长度不符合要求,不应该少于"+Minl+"个字符或多于"+Maxl+"个字符");
        obj.focus();
        return false;
    }
}

function checkQQ(obj,Minl,Maxl,hideCode)
{
    //验证QQ程序
    var objvalue=obj.value;
    var reg=/[1-9^0]\d{5,10}/
    if(!reg.test(objvalue))
        {
            alert("QQ必须为5-10位数字,且第一个数字不能为0");
            return false;
        }
}

//调用程序
function thisForm()
{
var iptName=document.getElementById("name");
var iptpassword=document.getElementById("password");
var iptpassword2=document.getElementById("password2"); //password2为确认密码
var iptEmail=document.getElementById("Email");
var iptQQ=document.getElementById("QQ");
if(checkform("name",iptName,6,16,""))
    {
        return false;
    }
if(checkform("password",iptName,4,10,""))
    {
        return false;
    }
if(checkform("email",iptEmail,10,30,""))
    {
        return false;
    }   
if(checkform("QQ",iptQQ,5,10,""))
    {
        return false;
    }   
}
</script>
</head>

<body>
    </td>
    <td width="235"  style="font-size:12px; color:#f00;" align="right">
      <div align="center" class="style5" id="Clock">
        <div align="left">
          <script>
<FORM ACTION="<%=MM_editAction%>" METHOD="POST" name=Form onSubmit="return thisForm()">
  <TABLE width=767 border=0 align="center" cellpadding="0" cellspacing="3" bgcolor="#CCFFFF" style="FONT-SIZE: 12px">
    <TBODY>
      <TR>
        <TD width="177" align=right><div align="right"><span class="style9">用户名:</span></div></TD>
        <TD width="169">
          <div align="left">
            <input name="name" type="text" id="name2">
        </div></TD>
        <TD width="391">
          <DIV id=test1Tip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
            <div align="left">选择一个您喜欢的6到12位用户名</div>
        </DIV></TD>
      </TR>
      <TR>
        <TD align=right><span class="style9">密码:</span></TD>
        <TD><div align="left">
            <input name="password" type="password" id="password">
        </div></TD>
        <TD width="391">
          <DIV id=test1Tip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
            <div align="left">您的密码(4到10位)</div>
        </DIV></TD>
      </TR>
      <TR>
        <TD align=right><span class="style9">重复密码:</span></TD>
        <TD><div align="left">
            <input name="password2" type="password" id="password2">
        </div></TD>
        <TD width="391">
          <DIV id=test1Tip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
            <div align="left">重复您的密码</div>
        </DIV></TD>
      </TR>
      <TR>
        <TD align=right><span class="style9">你的性别:</span></TD>
        <TD>
          <div align="left">
            <input name=sex type=radio id=radio value=男 checked>
            <span class="style5"> 男
            <input id=sex1 type=radio value=女 name=sex>
            
            <input type="radio" name="sex" value="保密">
            保密 </span></div></TD>
        <TD>
          <DIV id=sexTip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
            <div align="left">选择性别</div>
        </DIV></TD>
      </TR>
      <TR>
        <TD align=right><span class="style9">你的年龄:</span></TD>
        <TD><div align="left">
            <input name="age" type="text" id="age">
        </div></TD>
        <TD width="391">
          <DIV id=test1Tip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
            <div align="left">您的年龄</div>
        </DIV></TD>
      </TR>
      <TR>
        <TD align=right><div align="right" class="style9">出生日期:</div></TD>
        <TD><div align="left">
            <input name="born" type="text" id="born">
        </div></TD>
        <TD>
          <DIV id=csnyTip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
            <div align="left">日期的有效形式为:1982-09-21</div>
        </DIV></TD>
      </TR>
      <TR>
        <TD align=right><div align="right" class="style9">QQ:</div></TD>
        <TD><div align="left">
            <input name="QQ" type="text" id="QQ">
        </div></TD>
        <TD>
          <DIV id=sfzhTip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
            <div align="left">由6到10位数字组成的QQ号</div>
        </DIV></TD>
      </TR>
      <TR>
        <TD align=right><span class="style9">电子邮箱:</span></TD>
        <TD><div align="left">
            <input name="email" type="text" id="email">
        </div></TD>
        <TD>
          <DIV id=emailTip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
            <div align="left">有效的电子邮箱地址</div>
        </DIV></TD>
      </TR>
      <TR>
        <TD align=right><span class="style9">你的学历:</span></TD>
        <TD>
          <div align="left">
            <select name=record id=select>
              <option selected>-请选择学历-</option>
              <option value="高中">高中</option>
              <option value="专科">专科</option>
              <option value="本科">本科</option>
              <option value="研究生">研究生</option>
              <option value="硕士">硕士</option>
              <option value="博士">博士</option>
            </select>
        </div></TD>
        <TD>
          <DIV id=xueliTip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
            <div align="left">请选择您的学历</div>
        </DIV></TD>
      </TR>
      <TR>
        <TD align=right><span class="style9">密码问题提示:</span></TD>
        <TD><div align="left">
            <input name="question" type="text" id="question">
        </div></TD>
        <TD>
          <DIV id=shoujiTip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
            <div align="left">忘记密码找回时用。如:我的名字</div>
        </DIV></TD>
      </TR>
      <TR>
        <TD align=right><span class="style9">密码问题答案:</span></TD>
        <TD>
          <div align="left">
            <input name="answer" type="text" id="answer">
        </div></TD>
        <TD>
          <DIV id=lxdhTip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
            <div align="left">找回密码。答案如:王杰</div>
        </DIV></TD>
      </TR>
      <TR>
        <TD align=right><span class="style5">MSN</span><span class="style9">:</span></TD>
        <TD><div align="left">
            <input name="msn" type="text" id="msn">
        </div></TD>
        <TD width="391">
          <DIV id=test1Tip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
            <div align="left">您的MSN帐号</div>
        </DIV></TD>
      </TR>
      <TR>
        <TD align=right><span class="style5"><span class="style9">个人主页:</span></span></TD>
        <TD><div align="left">
            <input name="url" type="text" id="url" value="http://">
        </div></TD>
        <TD width="391">
          <DIV id=test1Tip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
            <div align="left">您的网页地址</div>
        </DIV></TD>
      </TR>
      <TR>
        <TD align=right vAlign=top><span class="style9">你的描述:</span></TD>
        <TD vAlign=top colSpan=2><div align="left">
            <TEXTAREA name="content" cols=50 rows=10>这个人比较懒,什么也没有留下。</TEXTAREA>
        </div></TD>
      </TR>
      <TR>
        <TD colspan="3" align=right vAlign=top><div align="center">
            <INPUT name="submit" type=submit id=button2 value=同意注册协议,现在注册 >
            <input type="reset" name="Submit" value="重置">
            <span class="style5"><a href="../index.asp">返回</a></span></div></TD>
      </TR>
    </TBODY>
  </TABLE>
  <p align="center">
    <input type="hidden" name="MM_insert" value="Form">
  </p>
</form>
<table width="816" border="0" align="center" cellspacing="1">
  <tr>
    <td width="812"><div align="center">
        <p align="center" class="style4">本站部分内容收集于互联网,如果有不妥之处,敬请谅解。如有侵权内容,请联系我们删除。</p>
        <p align="center" class="style4">Copyright &copy; 2008-2018 , All Rights Reserved</p>
        <p align="center"><span class="style37"><a href="http://www.miibeian. class="style4">辽ICP备08007090号</a></span></p>
    </div></td>
  </tr>
</table>
<p align="center">&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
请各位大侠帮忙给指出如何修改,先谢谢了!!!
搜索更多相关主题的帖子: 页面 注册 输入 
2008-10-01 22:36
lyg540612
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-8-12
收藏
得分:0 
用户名、密码、Email、QQ等项其中一个或几个必填项输入有错误时出现完各个提示错误信息后就出现如下错误:
“错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Microsoft Access Driver] 字段 'user.name' 不能是零长度的字符串。”
如何实现只出现提示错误信息,并返回此注册页面呢?谢谢了,我是个菜鸟,太笨了!!!
2008-10-01 22:42
frankqnj
Rank: 4
等 级:贵宾
威 望:12
帖 子:320
专家分:278
注 册:2008-4-6
收藏
得分:0 
转到 asp版问吧... 再说您这样问.. 我们看您的东西 象看小说一样...   没那么多时间...
提问题, 也请注意下方法啊. 毕竟大家是 义务帮您找问题..
2008-10-01 22:44
lyg540612
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-8-12
收藏
得分:0 
谢谢了
2008-10-02 08:46
快速回复:求助:输入错误时不能返回注册页面
数据加载中...
 
   



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

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