PHPjQuery实现异步处理用户注册Word下载.docx
- 文档编号:18021767
- 上传时间:2022-12-12
- 格式:DOCX
- 页数:11
- 大小:190.36KB
PHPjQuery实现异步处理用户注册Word下载.docx
《PHPjQuery实现异步处理用户注册Word下载.docx》由会员分享,可在线阅读,更多相关《PHPjQuery实现异步处理用户注册Word下载.docx(11页珍藏版)》请在冰豆网上搜索。
外框代码:
index.php>
include_once("
config.php"
styletype="
text/css"
!
--
#all{
border:
1pxsolidblack;
width:
400px;
background-color:
#808080;
}
#title{
margin-left:
300px;
margin-top:
10px;
#titlea{
text-decoration:
none;
color:
black;
#area{
0pxsolidblack;
height:
-->
/style>
scriptlanguage="
javascript"
type="
text/javascript"
src="
/example/jquery-1.8.2.js"
/script>
/example/register.js"
divid="
all"
<
title"
<
ahref="
#"
id="
reg"
注册<
/a>
log"
登录<
/div>
area"
用户注册页面代码:
register.php>
../config.php"
#userreg{
380px;
200px;
margin:
orange;
#list{
350px;
100px;
padding:
#listinput{
120px;
24px;
#button{
50px;
#buttoninput{
formaction="
method="
post"
由于使用了jquery提交,因此不再需要使用form表单提交,否则可能会出现:
有时候能把注册信息写进数据库,有时候不能;
当注册成功后,有时候能弹出提示框,有时候不能
userreg"
list"
用户名:
inputtype="
text"
name="
reguser"
/>
br>
密&
nbsp;
&
码:
password"
regpw"
button"
submit"
regbut"
value="
注册"
regb"
/form>
注册页面效果:
当在主页面点击注册按钮(
)后,页面底部会出现用户注册页面,实现代码
实现用户注册和注册信息写进数据库:
检测用户是否存在:
check_reg.php>
if($_POST['
u_name'
]){
$name=$_POST['
];
$pw=$_POST['
u_pw'
$sql="
select*fromtb_adminwhereuser='
$name'
;
$que=mysql_query($sql);
$num=mysql_num_rows($que);
if($num>
=1){
echo0;
}
else{
echo"
u_name="
.$name."
u_pw="
.$pw;
}
添加新用户:
check_regin.php>
]&
$_POST['
$pw=md5($_POST['
]);
$sq="
insertintotb_admin(id,user,password)"
."
values('
'
'
$pw'
)"
if(mysql_query($sq)){
echo1;
使用jQuery实现用户信息检测和提交:
register.js>
$(document).ready(function(){
$("
#reg"
).click(function(){
$.ajax({
url:
../example/reg/register.php"
cache:
false,
type:
POST"
success:
function(data){$("
#area"
).html(data);
});
});
#regb"
).live('
click'
function(){
varuser=$.trim($("
#reguser"
).val());
varpw=$.trim($("
#regpw"
if(user=="
){
$("
).focus();
alert("
输入用户名!
returnfalse;
if(pw=="
输入密码!
/*check_reg.php文件为判断用户是否被注册,check_regin.php文件为新用户注册并把信息加进数据库,检测用户和增加用户两个功能要分开两个php写,否则会出现问题*/
pass="
+user;
$.post("
../example/reg/check_reg.php"
pass,function(data){
if(data==0){
alert("
用户已存在!
}
else{
$.post("
../example/reg/check_regin.php"
pass+"
+pw,function(data){
if(data==1){
alert("
写入成功!
}
});
});
html、js和php之间的数据传递:
(1)js获取html文件中的id值(用户姓名reguser和密码regpw)文件
(2)js文件通过$.post(或$.get)方法把值传递给php文件
其中pass的值是获取的user值赋给u_name,把pass的值传到check_reg.php文件,check_reg.php使用$_POST方法获取js传过来的u_name值
同时check_reg.php文件进行判断,并把值通过echo输出
(3)js文件接收到php传过来的值后进行判断再做出相应处理
data即为php传过来的值
实现效果:
点击注册按钮
在没有输入用户信息的情况下会出现输入提示框
当注册成功会出现成功提示框
数据库数据变化:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- PHPjQuery 实现 异步 处理 用户 注册