Php Login issue
<p>Following is my php login script, There are one problem. If i put any password then it's doesn't validate the password and it's going to user panel page. where is the wrong in my code, can anyone tell me the right direction</p>

<p>N:B: I'M NEW IN PHP ALSO NEW IN THIS SITE.</p>

<pre><code>&lt;?php
if(isset($_POST['action']) &amp;&amp; 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) &amp;&amp; isset($pass))
{
    if(empty($uname) &amp;&amp; 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 "&lt;font color=red&gt;$er&lt;br&gt;&lt;/font&gt;";
    }   
}
else
{   
     include("user/include/newsession.php");                   
         header("Location:user/index.php");                     

}

}
?&gt; 
</code></pre>
