$.ajax({
type: "POST",
url: "__URL__/ajax",
data: "act=CkUser&username="+$('#username').val()+"&userid="+$('#userid').val(),
success: function(msg){
if(msg>0){
alert("用户名已存在!")
$('#username').val('')
}
}
})
}
<input name="username" type="text" class="input" id="username" size="20" value="{$rs.username}" onblur="CkUser()" />
<php>
$act = trim($_POST["act"])
switch($act)
{
case "CkUser":
$username = trim($_POST["username"])
$userid = intval($_POST["userid"])
$db = M("userinfo")
$num = $db->where("username='$username' and userid!=$userid and isdel=0")->count()
echo $num
break
}
要连接数据库一定要使用动态脚本语言,比如php、asp、jsp等等。DW只是一个工具,它支持这些语言,但要真正掌握好,灵活运用,必须得对这些语言有所了解。比如用php连接SQL Server的脚本大概如下:
<?php
$serverName = "SQLServer服务器IP地址"
$uid = "SQLServer有效用户"
$pwd = "密码"
$connectionInfo = array("UID"=>$uid,
"PWD"=>$pwd,
"Database"=>"默认数据库")
/* Connect using SQL Server Authentication. */
$conn = sqlsrv_connect($serverName, $connectionInfo)
if( $conn === false )
{
echo "Unable to connect.</br>"
die( print_r(sqlsrv_errors(), true))
}
?>
html是不可以实现的,如果可以也是嵌套的框架页面,接下来我把我做过的asp的代码贴给你,自己对照着看一下,有些不要的字段可以删除!
----------------------------------------------------------------------------------------------------
注册页面
<form action="registernew.asp" name="logform" method="post">
<table cellpadding="0" cellspacing="0" border="0" align="center" width="400">
<tbody>
<tr><td height="50" colspan="2" class="tabletitle">在线图书销售管理系统--新用户注册</td>
</tr>
<tr>
<td height="40" align="right" width=30% class="leftborder"><div class="STYLE6">用户名:</div></td>
<td width=70% align="center" class="rightborder">
<input name="username" type="text" class="textinput" value='<%=request("username")%>' maxlength="20">
<font color="red">*</font></div></td>
</tr>
<tr>
<td height="40" align="right" class="leftborder"><div class="STYLE6">口 令:</div></td>
<td align="center" class="rightborder">
<input name="userpwd1" type="password" class="textinput" value='<%=request("userpwd1")%>' maxlength="10">
<font color="red">*</font></div></td>
</tr>
<tr>
<td height="40" class="leftborder" align="right"><div class="STYLE6">重复口令:</div></td>
<td align="center" class="rightborder">
<input name="userpwd2" type="password" class="textinput" value='<%=request("userpwd2")%>' maxlength="10">
<font color="red">*</font></div></td>
</tr>
<tr>
<td height="40" align="right" class="leftborder"><div class="STYLE6">身份z号:</div></td>
<td align="center" class="rightborder">
<input name="useridentity" type="text" class="textinput " value='<%=request("useridentity")%>' maxlength="18">
<font color="red">*</font></div></td>
</tr>
<tr>
<td height="40" align="right" class="leftborder"><div class="STYLE6">电子邮件:</div></td>
<td align="center" class="rightborder">
<input name="useremail" type="text" class="textinput " value='<%=request("useremail")%>' maxlength="50">
<font color="red">*</font></div></td>
</tr>
<tr>
<td height="40" align="right" class="leftborder"><div class="STYLE6">联系电话:</div></td>
<td align="center" class="rightborder">
<input name="userphone" type="text" class="textinput " value='<%=request("userphone")%>' maxlength="11">
<font color="red">*</font></div></td>
</tr>
<tr>
<td height="40" align="right" class="leftborder"><div class="STYLE6">联系地址:</div></td>
<td align="center" class="rightborder">
<input name="useraddress" type="text" class="textinput" value='<%=request("useraddress")%>' maxlength="50">
<font color="red">*</font></div></td>
</tr>
<tr>
<td height="40" align="right" class="leftborder"><div class="STYLE6">邮政编码:</div></td>
<td align="center" class="rightborder">
<input name="userpostcode" type="text" class="textinput " value='<%=request("userpostcode")%>' maxlength="6">
<font color="red">*</font></div></td>
</tr>
<tr>
<td height="40" colspan="2" align="center" class="bottomborder leftborder rightborder"><input name="logbutton" type="button" value="注 册" onClick="checkform()"> <a href="default.asp">返回主页</a></td>
</tr>
</tbody>
</table>
</form>
<%
if request("username")<>"" then '保存用户注册信息
'建立数据库链接
set cn=server.CreateObject("adodb.connection")
cn.connectionstring="Driver={Microsoft Access Driver (*.mdb)}DBQ=" &Server.MapPath("/book/database/booksale.mdb/")
cn.open
'检查用户名是否重复
username=request("username")
set rs=server.createobject("adodb.recordset")
querystr="select * from customer where user_name='"&username&"'"
set rs.activeconnection=cn
rs.cursortype=1
rs.locktype=3
rs.open querystr
if rs.recordcount >0 then
response.write"<div align=center><font color=red>用户名重复!</font></div>"
else
'保存用户注册信息
rs.addnew
rs.fields("user_name")=request("username")
rs.fields("user_pwd")=request("userpwd1")
rs.fields("user_identity")=request("useridentity")
rs.fields("user_email")=request("useremail")
rs.fields("user_phone")=request("userphone")
rs.fields("user_address")=request("useraddress")
rs.fields("user_postcode")=request("userpostcode")
rs.update
session("username")=username '保存当前用户名
'自动载入在线图书销售管理系统页面
response.Redirect "booksaling.htm"
end if
'释放ado对象
rs.close
cn.close
set rs=nothing
set cn=nothing
response.flush
end if
%>
</body>
</html>
<script >
<!--
function checkform()
{
var uname=document.logform.username
var upwd=document.logform.userpwd1
var upwd2=document.logform.userpwd2
var uinentity=document.logform.useridentity
var uemail=document.logform.useremail
var uphone=document.logform.userphone
var uaddress=document.logform.useraddress
var upostcode=document.logform.userpostcode
if(uname.value.length==0){alert("请输入用户名!")return false}
else if(upwd.value.length==0){alert("请输入密码!")return false}
else if(upwd2.value!=upwd.value){alert("两次密码须一致!")return false}
else if(uinentity.value.length==0){alert("请输入身份z号!")return false}
else if (uemail.value.length ==0){alert("请输入电子邮箱!")return false}
else if(uemail.value.length >0){
var emailStr=uemail.value
var emailPat=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
var matchArray=emailStr.match(emailPat)
if (matchArray==null)
{alert("邮箱格式不正确!")
return false
}}
else if(uphone.value.length==0){alert("请输入联系电话!")return false}
else if(uaddress.value.length==0){alert("请输入联系地址!")return false}
else if(upostcode.value.length==0){alert("请输入邮编!")return false}
else {
return true}}
-->
</script>
-------------------------------------------------------------------------------------------------
信息读取页面
<form action="edituserinfo.asp" name="updateform" method="post">
<table cellpadding="2" align="center">
<tr>
<td align="right">用户名:</td>
<td><input name="updatename" id="uname" type="text" class="inputtext" maxlength="20" value="<%=updatename%>">
<font color="red">*</font></td>
</tr>
<tr>
<td align="right">口 令:</td>
<td><input name="updatepwd1" type="password" id="upassword" class="inputtext" value="<%=updatepwd%>" maxlength="10">
<font color="red">*</font></td>
</tr>
<tr>
<td></td>
<td><input name="updatepwd2" type="password" id="upassword2"class="inputtext" value="<%=updatepwd%>" maxlength="10">
<font color="red">*</font></td>
</tr>
<tr>
<td align="right">身份z号:</td>
<td><input name="updateidentity" type="text" id="uidentity" class="inputtext" value="<%=updateidentity%>" maxlength="18">
<font color="red">*</font></td>
</tr>
<tr>
<td align="right">电子邮件:</td>
<td><input name="updateemail" type="text" id="uemail" class="inputtext" value="<%=updateemail%>" maxlength="50">
<font color="red">*</font></td>
</tr>
<tr>
<td align="right">联系电话:</td>
<td><input name="updatephone" type="text" id="uphone" class="inputtext" value="<%=updatephone%>" maxlength="11">
<font color="red">*</font></td>
</tr>
<tr>
<td align="right">联系地址:</td>
<td><input name="updateaddress" type="text" id="uaddress" class="inputtext" value="<%=updateaddress%>" maxlength="50">
<font color="red">*</font></td>
</tr>
<tr>
<td align="right">邮政编码:</td>
<td><input name="updatepostcode" type="text" id="upostcode" class="inputtext" value="<%=updatepostcode%>" maxlength="6">
<font color="red">*</font></td>
</tr>
<tr>
<td colspan="2" align="center"><input name="updatebutton" id="updatebutton" type="button" value="保存修改的注册信息" onClick="ValidateUpdateForm()"></td>
</tr>
</table>
</form>
<%
if request("updatename")<>"" then '保存修改后的注册信息
querystr="select * from customer where user_name='"&request("updatename")&"'"
'创建recordset对象
set rstemp=server.CreateObject("adodb.recordset")
set rstemp.activeconnection=cn
rstemp.cursortype=1
rstemp.locktype=3
'检查用户名是否重复
rstemp.open querystr
if not rstemp.eof then
if rstemp.fields("user_id")<>rs.fields("user_id") then
response.write "<div align=center>"
response.write "<font color=red>用户名重复!</font></div>"
else
'保存修改后的用户注册信息
rs.fields("user_name")=request("updatename")
rs.fields("user_pwd")=request("updatepwd1")
rs.fields("user_identity")=request("updateidentity")
rs.fields("user_email")=request("updateemail")
rs.fields("user_phone")=request("updatephone")
rs.fields("user_address")=request("updateaddress")
rs.fields("user_postcode")=request("updatepostcode")
rs.update
session("username")=request("updatename") '保存修改后的用户名
response.write "<div align=center><font color=red>"
response.write "修改后的注册信息已被成功保存!</font></div>"
end if
else
'保存修改后的用户注册信息
rs.fields("user_name")=request("updatename")
rs.fields("user_pwd")=request("updatepwd1")
rs.fields("user_identity")=request("updateidentity")
rs.fields("user_email")=request("updateemail")
rs.fields("user_phone")=request("updatephone")
rs.fields("user_address")=request("updateaddress")
rs.fields("user_postcode")=request("updatepostcode")
rs.update
session("username")=request("updatename") '保存当前用户修改后的用户名
response.write "<div align=center><font color=red>"
response.write "修改后的注册信息已被成功保存!</font></div>"
end if
'释放ado对象
rstemp.close
rs.close
cn.close
set rs=nothing
set cn=nothing
set rstemp=nothing
response.Flush
end if
%>
<hr>
<div align="center"><a href="booksaling.htm">返回首页</a></div>
<% else %>
请登录后再访问该页面,到
<a href="default.asp" target="_parent">客户登陆</a>页面
<%end if%>
------------------------------------------------------------------------------------
数据库设计
customer表
字段如下:
user_id 自动编号,自增量1
user_name 用户名
user_pwd 密码
user_identity身份z号码
user_email 电子邮件
user_phone 联系方式
user_address 地址
user_postcode 邮编
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)