PHP+AJAX实现无刷新注册(带用户名实时检测)
(编辑:jimmy 日期: 2024/11/19 浏览:3 次 )
很多时候,我们在网上注册个人信息,在提交完页面后,总得等待页面刷新来告诉我们注册是否成功,遇到网络差的时候,如果注册了一大串的东西,在经过漫长的等待页面刷新后,得到的确是“您的用户名已被使用”或XXXXXXX不合法,我想大家的心情一定特别不爽,今天就介绍个AJAX实现页面不刷新注册+实时检测用户信息的简单注册程序,希望对大家有所帮助。好的,先看注册界面代码:
<table width="831" border="0" align="center" cellpadding="0" cellspacing="0">
<tr style="display:none">
<td height="35" align="center" id="result"> </td>
</tr>
</table>
<table width="100%" height="256" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td width="150" align="left" bgcolor="#FFFFFF"> · 用户名称: </td>
<td width="310" align="center" bgcolor="#FFFFFF">
<input name="username" type="text" class="inputtext" id="username" >
<font color="#FF6633">*</font></td>
<td align="left" bgcolor="#FFFFFF" id="check"> 4-16个字符,英文小写、汉字、数字、最好不要全部是数字。</td>
</tr>
<tr>
<td width="150" align="left" bgcolor="#FFFFFF"> · 用户密码:</td>
<td width="310" align="center" bgcolor="#FFFFFF">
<input name="userpwd" type="password" class="inputtext" id="userpwd" >
<font color="#FF6633">*</font> </td>
<td align="left" bgcolor="#FFFFFF" id="pwd"> 密码字母有大小写之分。6-16位(包括6、16),限用英文、数字。</td>
</tr>
<tr>
<td width="150" align="left" bgcolor="#FFFFFF"> · 重复密码:</td>
<td width="310" align="center" bgcolor="#FFFFFF">
<input name="reuserpwd" type="password" class="inputtext" id="reuserpwd" >
<font color="#FF6633">*</font> </td>
<td align="left" bgcolor="#FFFFFF" id="repwd"> 请再次输入登录密码。</td>
</tr>
</table>
如图:
}
$db->close();//关闭数据库连接
?>
注释写的还算详细,大家应该都能看懂,再看信息合法后我们提交注册信息实现无刷新注册的PHP代码,senduserinfo.php:
<?php
header('Content-Type:text/html;charset=GB2312');//避免输出乱码
include('inc/config.inc.php');//包含数据库基本配置信息
include('inc/dbclass.php');//包含数据库操作类
$username=trim($_GET['username']);//获取注册名
$userpwd=md5(trim($_GET['userpwd']));//获取注册密码
$time=date("Y-m-d");
//-----------------------------------------------------------------------------------
$db=new db;//从数据库操作类生成实例
$db->mysql($dbhost,$dbuser,$dbpassword,$dbname);//调用连接参数函数
$db->createcon();//调用创建连接函数
//-----------------------------------------------------------------------------------
//开始插入数据
//-----------------------------------------------------------------------------------
$addsql="insert into cr_userinfo values(0,'$username','$userpwd','$time',50,1,'$userquestion','$useranswer')";
$db->query($addsql);
echo"<img src=images/pass.gif> <font color=red>恭喜您,注册成功!请点击<a href=login.php>这里</a>登录!</font>";
$db->close();//关闭数据库连接
?>
OK!!大功告成,来看看效果图:
1.
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0>
2.
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0>
3.
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0>
4.
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0>
5.
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0>
怎么样?还不错吧,贴了这么多累死了,希望大家喜欢~~~~
<table width="831" border="0" align="center" cellpadding="0" cellspacing="0">
<tr style="display:none">
<td height="35" align="center" id="result"> </td>
</tr>
</table>
<table width="100%" height="256" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td width="150" align="left" bgcolor="#FFFFFF"> · 用户名称: </td>
<td width="310" align="center" bgcolor="#FFFFFF">
<input name="username" type="text" class="inputtext" id="username" >
<font color="#FF6633">*</font></td>
<td align="left" bgcolor="#FFFFFF" id="check"> 4-16个字符,英文小写、汉字、数字、最好不要全部是数字。</td>
</tr>
<tr>
<td width="150" align="left" bgcolor="#FFFFFF"> · 用户密码:</td>
<td width="310" align="center" bgcolor="#FFFFFF">
<input name="userpwd" type="password" class="inputtext" id="userpwd" >
<font color="#FF6633">*</font> </td>
<td align="left" bgcolor="#FFFFFF" id="pwd"> 密码字母有大小写之分。6-16位(包括6、16),限用英文、数字。</td>
</tr>
<tr>
<td width="150" align="left" bgcolor="#FFFFFF"> · 重复密码:</td>
<td width="310" align="center" bgcolor="#FFFFFF">
<input name="reuserpwd" type="password" class="inputtext" id="reuserpwd" >
<font color="#FF6633">*</font> </td>
<td align="left" bgcolor="#FFFFFF" id="repwd"> 请再次输入登录密码。</td>
</tr>
</table>
如图:
}
$db->close();//关闭数据库连接
?>
注释写的还算详细,大家应该都能看懂,再看信息合法后我们提交注册信息实现无刷新注册的PHP代码,senduserinfo.php:
<?php
header('Content-Type:text/html;charset=GB2312');//避免输出乱码
include('inc/config.inc.php');//包含数据库基本配置信息
include('inc/dbclass.php');//包含数据库操作类
$username=trim($_GET['username']);//获取注册名
$userpwd=md5(trim($_GET['userpwd']));//获取注册密码
$time=date("Y-m-d");
//-----------------------------------------------------------------------------------
$db=new db;//从数据库操作类生成实例
$db->mysql($dbhost,$dbuser,$dbpassword,$dbname);//调用连接参数函数
$db->createcon();//调用创建连接函数
//-----------------------------------------------------------------------------------
//开始插入数据
//-----------------------------------------------------------------------------------
$addsql="insert into cr_userinfo values(0,'$username','$userpwd','$time',50,1,'$userquestion','$useranswer')";
$db->query($addsql);
echo"<img src=images/pass.gif> <font color=red>恭喜您,注册成功!请点击<a href=login.php>这里</a>登录!</font>";
$db->close();//关闭数据库连接
?>
OK!!大功告成,来看看效果图:
1.
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0>
2.
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0>
3.
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0>
4.
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0>
5.
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0>
怎么样?还不错吧,贴了这么多累死了,希望大家喜欢~~~~
下一篇:php字符串截取问题