PHP 表单验证,,为什么总是提示验证码错误,而不是先判定用户名和密码 5
session_start();if(isset($_POST['denglu'])){echo"<script>alert('".$_SESSION['randcode...
session_start();
if(isset($_POST['denglu']))
{
echo "<script>alert('".$_SESSION['randcode']."');</script>";
$username=$_POST['username'];
$password=$_POST['password'];
$randcode=$_POST['yanzheng'];
if($username!="账号/密码"&&$password!="")
{
if($_SESSION['randcode']==$randcode)
{$conn=mysql_connect("localhost","root","");
mysql_select_db("phpwork",$conn);
mysql_query("set names gb2312");
$sql="select * from 'userinfo' where username='$username'";
$checkuser=mysql_query($sql,$conn);
$rows=mysql_num_rows($checkuser);
$res=mysql_fetch_array($checkuser);
if(intval($rows)==0){echo "<script>function checktext(){alert('不存在的账号');return false;}</script>";}
else if($password!=$res[userpwd]){echo "<script>function checktext(){alert('密码错误');return false;}</script>";}
else {$_SESSION['username']=$username;
$_SESSION['password']=$password; echo "<script>function checktext(){return true;}</script>";}
}
else {echo "<script>function checktext() {alert('验证码错误');return false;}</script>";}
}
else {echo "<script>function checktext()
{
if(login.username.value==''||login.username.value=='账号/密码'){
alert('请输入账号');
return false;
}
else if(login.password.value==''){
alert('请输入密码');
return false;}
}</script>";
}
} 展开
if(isset($_POST['denglu']))
{
echo "<script>alert('".$_SESSION['randcode']."');</script>";
$username=$_POST['username'];
$password=$_POST['password'];
$randcode=$_POST['yanzheng'];
if($username!="账号/密码"&&$password!="")
{
if($_SESSION['randcode']==$randcode)
{$conn=mysql_connect("localhost","root","");
mysql_select_db("phpwork",$conn);
mysql_query("set names gb2312");
$sql="select * from 'userinfo' where username='$username'";
$checkuser=mysql_query($sql,$conn);
$rows=mysql_num_rows($checkuser);
$res=mysql_fetch_array($checkuser);
if(intval($rows)==0){echo "<script>function checktext(){alert('不存在的账号');return false;}</script>";}
else if($password!=$res[userpwd]){echo "<script>function checktext(){alert('密码错误');return false;}</script>";}
else {$_SESSION['username']=$username;
$_SESSION['password']=$password; echo "<script>function checktext(){return true;}</script>";}
}
else {echo "<script>function checktext() {alert('验证码错误');return false;}</script>";}
}
else {echo "<script>function checktext()
{
if(login.username.value==''||login.username.value=='账号/密码'){
alert('请输入账号');
return false;
}
else if(login.password.value==''){
alert('请输入密码');
return false;}
}</script>";
}
} 展开
2个回答
展开全部
"<script>function checktext(){alert('不存在的账号');return false;}</script>你打印的是一个js自定义函数,没有定义;所以一直到校检验证码时前面即使出错也不会提示,并且继续往下执行,直到运行到检查验证码那一行时,如果验证码不对,他才报错,然后依次检查账号,密码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-05-23
展开全部
判断语句结构问题,把结构理清就好了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询