PHPjQuery实现异步处理用户注册.docx

上传人:b****4 文档编号:5063524 上传时间:2022-12-12 格式:DOCX 页数:11 大小:190.36KB
下载 相关 举报
PHPjQuery实现异步处理用户注册.docx_第1页
第1页 / 共11页
PHPjQuery实现异步处理用户注册.docx_第2页
第2页 / 共11页
PHPjQuery实现异步处理用户注册.docx_第3页
第3页 / 共11页
PHPjQuery实现异步处理用户注册.docx_第4页
第4页 / 共11页
PHPjQuery实现异步处理用户注册.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

PHPjQuery实现异步处理用户注册.docx

《PHPjQuery实现异步处理用户注册.docx》由会员分享,可在线阅读,更多相关《PHPjQuery实现异步处理用户注册.docx(11页珍藏版)》请在冰豆网上搜索。

PHPjQuery实现异步处理用户注册.docx

PHPjQuery实现异步处理用户注册

jQuery实现异步处理用户注册

数据库代码:

php

$conn=mysql_connect("localhost","root","")ordie("connecterror");

mysql_select_db("meal",$conn)ordie("connecterror");

mysql_query("setnames'UTF8'");

?

>

主体页面的功能:

当点击注册按钮后在页面底下区域显示用户注册。

外框代码:

php

include_once("config.php");

?

>

--

#all{

border:

1pxsolidblack;

width:

400px;

background-color:

#808080;

}

#title{

margin-left:

300px;

margin-top:

10px;

}

#titlea{

text-decoration:

none;

color:

black;

}

#area{

border:

0pxsolidblack;

margin-top:

10px;

width:

400px;

height:

300px;

}

-->

注册

登录

用户注册页面代码:

php

include_once("../config.php");

?

>

--

#userreg{

border:

1pxsolidblack;

width:

380px;

height:

200px;

margin:

10px;

background-color:

orange;

}

#list{

border:

0pxsolidblack;

width:

350px;

height:

100px;

margin:

10px;

padding:

10px;

}

#listinput{

width:

120px;

height:

24px;

margin-top:

10px;

}

#button{

border:

0pxsolidblack;

height:

50px;

width:

350px;

margin:

10px;

}

#buttoninput{

width:

50px;

margin-top:

10px;

}

-->

--

由于使用了jquery提交,因此不再需要使用form表单提交,否则可能会出现:

有时候能把注册信息写进数据库,有时候不能;当注册成功后,有时候能弹出提示框,有时候不能

-->

用户名:


密   码:

--

-->

注册页面效果:

当在主页面点击注册按钮(

)后,页面底部会出现用户注册页面,实现代码

实现用户注册和注册信息写进数据库:

检测用户是否存在:

php

include_once("../config.php");

if($_POST['u_name']){

$name=$_POST['u_name'];

$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;

}

}

?

>

添加新用户:

php

include_once("../config.php");

if($_POST['u_name']&&$_POST['u_pw']){

$name=$_POST['u_name'];

$pw=md5($_POST['u_pw']);

$sq="insertintotb_admin(id,user,password)"."values('','$name','$pw')";

if(mysql_query($sq)){

echo1;

}

}

?

>

使用jQuery实现用户信息检测和提交:

$(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").val());

if(user==""){

$("#reguser").focus();

alert("输入用户名!

");

returnfalse;

}

if(pw==""){

$("#regpw").focus();

alert("输入密码!

");

returnfalse;

}

/*check_reg.php文件为判断用户是否被注册,check_regin.php文件为新用户注册并把信息加进数据库,检测用户和增加用户两个功能要分开两个php写,否则会出现问题*/

pass="u_name="+user;

$.post("../example/reg/check_reg.php",pass,function(data){

if(data==0){

alert("用户已存在!

");

}

else{

$.post("../example/reg/check_regin.php",pass+"&u_pw="+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传过来的值

 

实现效果:

点击注册按钮

在没有输入用户信息的情况下会出现输入提示框

当注册成功会出现成功提示框

数据库数据变化:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1