donglin4636 2015-05-17 11:18
浏览 204
已采纳

mysql_num_rows变量保持值为NULL

$row = mysql_num_rows($result); has the value of 1 as expected. This is because the SQL query has found 1 row with the criteria. However, $row[3] is returning NULL when I was expecting a hash value. Any help will be appreciated. So my question is, why is $row[3] holding the value of null and not the hash value expected which is on my SQL database?

<?php 

    include('config.php');

    $email = $_POST['email'];
    $password = $_POST['password'];

    $query = "SELECT * FROM users WHERE email='$email';";
    $result = mysql_query($query);
    $row = mysql_num_rows($result);
    $password_relative = $row[3];

    echo "Row Value: ".$row."<br>";
    var_dump($password_relative); // holding null???
    var_dump($row); // holding 1 as intended

    echo "Inputed Password: ".$password."<br>";
    echo "Password Value On Server:".$password_relative."<br>";

    if ($row > 0) {
        // password_verify(password, hash);
        if(password_verify($password, $password_relative)) {
            // set seesion variables
            echo 'Successful sign in<a class="link" href="index.php">Go to dashboard</a>';
        } else {
            echo 'Password is wrong!<a class="link" href="SignIn.php">Go to sign in</a>';
        }
    } else {
        echo 'The details given show that you do not have an account with us<a class="link" href="SignIn.php">Go to sign in</a>';
    }

?>
  • 写回答

2条回答 默认 最新

  • drouie2014 2015-05-17 11:30
    关注

    mysql_* functions are deprecated, so please don't use them anymore. Use PDO_mysql or MySQLi instead.

    This being said, your $row var contains the number returned by mysql_num_rows(). It doesn't contain the row data.

    To get the row data array with numeric keys only, you would need to use mysql_fetch_row().

    More doc here : php.net mysql_fetch_row() documentation

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 CCF-CSP 2023 第三题 解压缩(50%)
  • ¥100 网页游戏在本地页面修改游戏结果
  • ¥30 comfyui openpose报错
  • ¥20 Wpf Datarid单元格闪烁效果的实现
  • ¥15 图像分割、图像边缘提取
  • ¥15 sqlserver执行存储过程报错
  • ¥100 nuxt、uniapp、ruoyi-vue 相关发布问题
  • ¥15 浮窗和全屏应用同时存在,全屏应用输入法无法弹出
  • ¥100 matlab2009 32位一直初始化
  • ¥15 Expected type 'str | PathLike[str]…… bytes' instead