Home > Backend Development > PHP Tutorial > PHP 新手有关问题!求诸位大侠指点迷津!

PHP 新手有关问题!求诸位大侠指点迷津!

WBOY
Release: 2016-06-13 10:21:07
Original
984 people have browsed it

PHP 新手问题!!求诸位大侠指点迷津!!
网上下了个开源项目学习 其中注册验证用户名唯一的地方有点问题 不知道那里出问题了。
JS 调用PHP 文件验证 但是不知道为什么会返回个0 不知道那里出错了。

JS代码:
function chkname(form){
if(form.name.value=="")
{
name1.innerHTML="请输入用户名!";
}
else
{
var user = form.name.value;

var url = "chkname.php?user="+user;

xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange = function()
{

if(xmlHttp.readyState == 4)
{
var msg = xmlHttp.responseText;
if(msg == '2'){
name1.innerHTML="用户名被占用!";
return false;
}else if(msg == '1'){
name1.innerHTML="恭喜您,可以注册!";
form.c_name.value = "yes";

}else{
name1.innerHTML=""+msg+"";
}
}
}
xmlHttp.send(null);
}
}

PHP代码:session_start();
include_once "conn/conn.php";
$reback = '0';
$sql = "select * from tb_user where name='".$_GET['user']."'";
$rst = $conn->Execute($sql) or die('execute error');
if($rst->RecordCount() == 0)
{

  $reback = '1';
}
else
{
$reback = '2';
}
echo $reback;
?>


------解决方案--------------------

探讨
$rst = $conn->Execute($sql) or die('execute error');
if($rst->RecordCount() == 0)

------解决方案--------------------
"php ajax 注册 源码"
http://www.baidu.com/s?bs=php+ajax+%D7%A2%B2%E1%B5%C7%C2%BD%CD%CB%B3%F6+%D4%B4%C2%EB&f=8&rsv_bp=1&wd=php+ajax+%D7%A2%B2%E1+%D4%B4%C2%EB&inputT=190
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template