如何测试用户名是否重复~需要添加什么代码

daleyvette 2011-07-21 03:37:02
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../Connections/sss.asp" -->
<%
Dim MM_editAction
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
Dim MM_abortEdit
MM_abortEdit = false
%>
<%
If (CStr(Request("MM_insert")) = "form1") Then
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd

Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_sss_STRING
MM_editCmd.CommandText = "INSERT INTO Form1 ([user], pass, confirmPassword, question, answer, email) VALUES (?, ?, ?, ?, ?, ?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 255, Request.Form("1")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 202, 1, 255, Request.Form("22")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 202, 1, 255, Request.Form("textfield4")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 202, 1, 255, Request.Form("textfield6")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 202, 1, 255, Request.Form("textfield7")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 202, 1, 255, Request.Form("textfield11")) ' adVarWChar
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
End If
End If
%>
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows

Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_sss_STRING
Recordset1_cmd.CommandText = "SELECT * FROM Form1 ORDER BY ID ASC"
Recordset1_cmd.Prepared = true

Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
<script LANGUAGE="JavaScript">
function aa()
{

if (document.Form1.user.value == "")
{
alert("请填写您的用户名!");
document.Form1.user.focus();
return (false);
}

var filter=/^\s*[.A-Za-z0-9_-]{5,15}\s*$/;
if (!filter.test(document.Form1.user.value)) {
alert("用户名填写不正确,请重新填写!可使用的字符为(A-Z a-z 0-9 _ - .)长度不小于5个字符,不超过15个字符,注意不要使用空格。");
document.Form1.user.focus();
document.Form1.user.select();
return (false);
}

if (document.Form1.pass.value =="")
{
alert("请填写您的密码!");
document.Form1.pass.focus();
return (false);
}

if(document.Form1.confirmPassword.value==""){
alert("请输入您的确认密码!");
document.Form1.confirmPassword.focus();
return (false);
}

var filter=/^\s*[.A-Za-z0-9_-]{5,15}\s*$/;
if (!filter.test(document.Form1.pass.value)) {
alert("密码填写不正确,请重新填写!可使用的字符为(A-Z a-z 0-9 _ - .)长度不小于5个字符,不超过15个字符,注意不要使用空格。");
document.Form1.pass.focus();
document.Form1.pass.select();
return (false);
}

if (document.Form1.pass.value!=document.Form1.confirmPassword.value ){
alert("两次填写的密码不一致,请重新填写!");
document.Form1.pass.focus();
document.Form1.pass.select();
return (false);
}

if (document.Form1.question.value == "")
{
alert("请输入密码提示问题!");
document.Form1.question.focus();
return (false);
}
if (document.Form1.answer.value == "")
{
alert("请输入密码提示答案!");
document.Form1.answer.focus();
return (false);
}

if (document.Form1.email.value == "")
{
alert("请输入您的电子邮件地址!");
document.Form1.email.focus();
document.Form1.email.select();
return (false);
}

var filter=/^\s*([A-Za-z0-9_-]+(\.\w+)*@(\w+\.)+\w{2,3})\s*$/;
if (!filter.test(document.Form1.email.value)) {
alert("邮件地址不正确,请重新填写!");
document.Form1.email.focus();
document.Form1.email.select();
return (false);
}


}
</script>


<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<form ACTION="<%=MM_editAction%>" METHOD="POST" name="Form1" onSubmit="return aa()">
<div align="center">
<h1><strong>注册页</strong></h1>
<table width="544" height="497" border="1">
<tr>
<td width="235">用户名</td>
<td width="238"><label for="22"></label>
<input type="text" name="user" id="user" /></td>
</tr>
<tr>
<td>密码</td>
<td><label for="confirmPassword"></label>
<input type="password" name="pass" id="22" /></td>
</tr>
<tr>
<td>再输入</td>
<td><label for="4"></label>
<input type="password" name="confirmPassword" id="textfield4" /></td>
</tr>
<tr>
<td height="64">question</td>
<td><label for="textfield6"></label>
<input type="text" name="question" id="question" /></td>
</tr>
<tr>
<td height="72">answer</td>
<td><label for="textfield7"></label>
<input type="text" name="answer" id="answer" />
<label for="textarea"></label></td>
</tr>
<tr>
<td>email</td>
<td><label for="textfield11"></label>
<input type="text" name="email" id="email" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="sub" value="注册" /></td>
</tr>
</table>
</div>
</form>

</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
...全文
131 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
daleyvette 2011-07-21
  • 打赏
  • 举报
回复
这个语句套嵌在哪里呢?
Dogfish 2011-07-21
  • 打赏
  • 举报
回复
select count(*) as items from users where username = 'abc'

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧