php ajax用户注册检测代码

啊哈,终于用PHP实现了登录和注册拉,但是问题又来了,要求用ajax和php结合实现登录注册油烟机清洗php登录源码:下面是chklogin.php页面代码:?phpsession_start();$connect=mysql_connect(127.0.0.1,root,123);if(!$connect){die(”Could
not connect: ” .
mysql_error());}mysql_select_db(design,$connect);$query=select *
from ta_user where user_name =”.$name.”;$result=mysql_query($query)
OR die(Unable to connect to
MySQL);$rows=mysql_fetch_array($result);if($rows[user_password]==$pwd){header(Location:login_suss.php?name=.$name.);}else{echo
table width=”235” height=”61” border=”0” align=”center”;echo
trtd height=”29”用户名或密码错误!/td/tr;echo trtd
height=”29”请点击a
href=”javascrīpt:history.go(-1);”这儿/a重新输入!;echo /td/tr;echo
/table;}?ajax:scrīpt language=javascrīptfunction getXMLHTTPRequest(){var
xRequest=null;if (window.XMLHttpRequest){xRequest=new
XMLHttpRequest();}else if (typeof ActiveXObject !=
undefined){xRequest=new ActiveXObject(Microsoft.XMLHTTP);}return
xRequest;}function Ajax(url){AjaxObj =
getXMLHTTPRequest();AjaxObj.onreadystatechange =
processRequest;AjaxObj.open(post,url,true);AjaxObj.setRequestHeader(”Content-type”,”application/x-”);AjaxObj.send(name+name);}function
processRequest(){if(AjaxObj.readyState == 4){if(AjaxObj.status ==
200){if(AjaxObj.responseText !=
){document.getElementById(show).innerHTML=;//alert(AjaxObj.responseText);document.getElementById(show).innerHTML=AjaxObj.responseText;}}else{alert(您所请求的页面有异常。<

php ajax用户注册检测代码

index.php 复制PHP内容到剪贴板 PHP代码:tr td width=25%
class=altbg1nbsp;nbsp;用 户 名font color=red*/fontbr //td td input
size=25 name=username type=text value=
onBlur=startRequest(document.getElementById(‘username’).value); / /td td
id=ckuser/td /tr

js:ajax.js 复制PHP内容到剪贴板 var xmlHttp; function
createXMLHttpRequest() { if(window.XMLHttpRequest) { xmlHttp = new
XMLHttpRequest();//mozilla浏览器 } else if(window.ActiveXObject) { try {
xmlHttp = new ActiveX0bject(Msxml2.XMLHTTP);//IE老版本 } catch(e) {} try
{ xmlHttp = new ActiveXObject(Microsoft.XMLHTTP);//IE新版本 } catch(e)
{} if(!xmlHttp) { window.alert(不能创建XMLHttpRequest对象实例); return
false; } } } php ajax用户注册检测代码 function startRequest(username) {
createXMLHttpRequest();//特编
xmlHttp.open(GET,ckuser.php?name=+username,true);
xmlHttp.onreadystatechange = handleStateChange; xmlHttp.send(null); }
function handleStateChange() { if(xmlHttp.readyState==4) {
if(xmlHttp.status==200) { //alert(来自服务器的响应: +
xmlHttp.responseText); if(xmlHttp.responseText == true){
document.getElementById(ckuser).innerHTML = ‘此用户名以被人注册’; } else
if(xmlHttp.responseText == false) {
document.getElementById(ckuser).innerHTML = ‘检测通过’; } } } }

ckuser.php php ajax用户注册检测代码PHP代码:?php// //require_once
globals.php; require_once config.inc.php; //require_once
‘common/common.php’; $username = $_GET[name]; $con =
@mysql_connect($dbserver,$dbuser,$dbpass )or die(无法连接到数据库!);
mysql_query(set names gbk); mysql_select_db($dbname,$con)or
die(无法选择数据库!); $query=select id from hj_member where
username=’.$username.’;; $res=mysql_query($query);
if(mysql_num_rows($res)!=0) { echo true; }else { echo false; }

?

发表评论

电子邮件地址不会被公开。 必填项已用*标注