免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1541 | 回复: 2
打印 上一主题 下一主题

php实现唯一校验咋老是有点错误 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-05-24 11:09 |只看该作者 |倒序浏览
这个是注册界面register.php
<title>注册页面</title>
<head>
<script language="javascript">
//JavaScript Document
var xmlHttp;
function S_xmlhttprequest()
{
xmlHttp=null;
if (window.XMLHttpRequest)
{// code for IE7, Firefox, Opera, etc.
xmlHttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE6, IE5
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}

function getName(name)
{

if(name = document.myform.name.value)
{
S_xmlhttprequest();
xmlHttp.open("get","date.php?name="+name,true);
xmlHttp.onreadystatechange = byname;
xmlHttp.send(null);
}

}

function byname()
{
if(xmlHttp.readyState ==1)
{
document.getElementById("name").innerHTML = "检测中......";
}
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
var name = xmlHttp.responseText;
document.getElementById("name").innerHTML ="name";
}
}
}
function getEmail(email)
{
var email = document.myform.email.value;
if(email =="")
{
alert("用户名不能为空");
document.myform.email.focus();
return false;
}
else
{
S_xmlhttprequest();
xmlHttp.open("get","date.php?email="+email,true);
xmlHttp.onreadystatechange = byemail;
xmlHttp.send(null);
}

}
function byemail()
{
if(xmlHttp.readyState ==1)
{
document.getElementById('email').innerHTML = "<font color=red>loading....</font>";
}
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
var email = xmlHttp.responseText;
document.getElementById('email').innerHTML = email;
}
}
}
</script>
</head>
<body>
<form action="" method="post" name="myform">
<table align="center">
<tr><td>用户名:</td><td><input type="text" name="name" value="" onblur="getName('name')"/>
</td><td><div id="name"><font color="#CC66CC">*用户名必填*</font></div></td></tr>
<tr><td>邮箱:</td><td><input type="text" name="email" value="" onblur="getEmail('email')"/>
</td><td><div id="email"><font color="#CC66CC">*邮箱必填*</font></div></td></tr>
</table>
</form>
</body>

而这个是数据验证代码date.php
  <?php
sleep(1);
$connt = mysql_connect("localhost","root","root");
mysql_select_db('people',$connt );
mysql_query("set names 'gb2312'");
if($_GET['name'])
{
$name = $_GET['name'];
$sql = "select * from tb_user where usernc='$name'";
$restul = mysql_query($sql);
$array = mysql_fetch_row($restul);
// print_r($array);
if(is_array($array))
{
echo "<font color='red'>该用户名已经存在</font>";
}
else
{
echo "<font color='red'>该用户名可以用</font>";
}
}
if($_GET['email'])
{
$name = $_GET['email'];
$sql = "select * from tb_user where email='$email'";
$restul = mysql_query($sql);
$array = mysql_fetch_row($restul);
// print_r($array);
if(is_array($array))
{
echo "<font color='red'>该邮箱已存在</font>";
}
else
{
echo "<font color='red'>该邮箱可以用</font>";
}
}

?>
希望给解决一下

论坛徽章:
0
2 [报告]
发表于 2011-05-24 12:30 |只看该作者
这是什么。。?


...
$name = $_GET['email'];
$sql = "select * from tb_user where email='$email'";
...

论坛徽章:
0
3 [报告]
发表于 2011-05-24 16:13 |只看该作者
这一块改了还是不行呀
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP