以下是我的php登录脚本,有一个问题。如果我输入任何密码,那么它不会验证密码,它会进入用户面板页面。我的代码哪里错了,谁能告诉我正确的方向
N:B: 我是 PHP 新手,也是这个网站的新手。
<?php
if(isset($_POST['action']) && isset($_POST['action']) == 'Log In')
{
$uname = mysql_real_escape_string(trim(htmlspecialchars($_POST['uname'])));
$pass = mysql_real_escape_string(trim(htmlspecialchars($_POST['pass'])));
$crytpass = hash('sha512','$pass');
$err = array();
include_once("toplevel/content/manage/dbcon/dbcon.php");
// check username
$check_uname = mysql_query("SELECT uname FROM members WHERE uname = '$uname'");
$num_uname = mysql_num_rows($check_uname);
// check password
$check_pass = mysql_query("SELECT pass FROM members WHERE pass = '$crytpass'");
$num_pass = mysql_num_rows($check_pass);
/// userid
$userid = mysql_query("SELECT userid FROM members");
$re = mysql_fetch_array($userid);
$userid = (int) $re['userid'];
if(isset($uname) && isset($pass))
{
if(empty($uname) && empty($pass))
$err[] = "All field required";
else
{
// username validation process....
if(empty($uname))
$err[] = "Username required";
else
{
if($num_uname == 0)
$err[] = "Username is not correct";
}
// password validaiton process...
if(empty($pass))
$err[] = "Password required";
else
{
if($num_pass == 0)
$err[] = "Password is not correct";
}
}
}
if(!empty($err))
{
foreach($err as $er)
{
echo "<font color=red>$er<br></font>";
}
}
else
{
include("user/include/newsession.php");
header("Location:user/index.php");
}
}
?>