如果$count等于1但不等于1,我的MySQL会话将启动
我不知道如何修复它,我对php还比较陌生,我更喜欢使用sha1
而不是BCrypt

  <?php
     //login form
     mysql_connect("xxxxx","xxxxxx","xxxxxx") or die( mysql_error() );
     mysql_select_db("u940004575_chat");

     $myusername = stripslashes( $myusername );
     $mypassword = stripslashes( $mypassword );
     $sha1mypassword = sha1( $mypassword );
     $myusername = mysql_real_escape_string( $myusername );
     $mypassword = mysql_real_escape_string( $mypassword );
     $sha1mypassword = mysql_real_escape_string( $sha1mypassword );
     $sql = mysql_query("SELECT id FROM users WHERE username='$myusername' and         password='$sha1mypassword'")or die( mysql_error() );
     $result = mysql_query( $sql );

     if ( $sql ) {
         $count = mysql_num_rows( $sql );
     }

     if ( $count == 1 ) {
        session_register("myusername");
        session_register("mypassword");
        header("location:home.php");
     } else {
        echo "Wrong Username or Password";
     }
?>

如果有人能帮助我,那将是伟大的,任何修复将非常感谢。

最佳答案

听着,一定是这样的:

 $sql = "SELECT id FROM users WHERE username = '$myusername' and password = '$sha1mypassword'";
 // you defined the sql query

 $result = mysql_query( $sql );
 // now you executed it and have the result

 // and you can go on with this result
 if ( $result ) {
     $count = mysql_num_rows( $result );
 }

顺便说一下,转到mysqli_query(),因为mysql_query()很快就会被弃用。见官方文件。

关于php - 我的MySQL session 无法启动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19040035/

10-10 23:17