【问题标题】:Call to undefined function MYSQL_NUM_ROWS() [duplicate]调用未定义的函数 MYSQL_NUM_ROWS() [重复]
【发布时间】:2016-11-13 09:17:14
【问题描述】:

我正在尝试使用 php 验证登录但收到此错误:

致命错误:未捕获的错误:调用 /opt/lampp/htdocs/social/index.php:100 中未定义的函数 MYSQL_NUM_ROWS() 堆栈跟踪:在 /opt/lampp/htdocs/social/ 中抛出 #0 {main}第 100 行的 index.php

这是我的代码

if(isset($_POST['login'])){

        $studentid = $_POST['studid'];  
        $pass = $_POST['password'];

        $query2 = mysqli_query($con, "SELECT * FROM members WHERE student_id = '$studentid' AND password = '$pass' ") or die (mysqli_connect_error());

        while($studid = mysqli_fetch_object($query2))
            {
            echo "$studid->member_id";
            }
            $numberOfRows = MYSQL_NUM_ROWS($query2);
            if ($numberOfRows == 0)
                {

                }
            else if ($numberOfRows > 0){
                    $wewness = mysql_query("SELECT * FROM members WHERE student_id = $studentid")or die(mysql_error());
                    $getid = mysql_fetch_array($wewness);
                    if($getid['account_status']==0){
                        $_SESSION['login'] = 'maybe';
                        $_SESSION['member_id'] = $getid['member_id'];
                        $_SESSION['studentid'] = $getid['student_id'];
                        header('location:registerexec.php');
                    }elseif($getid['account_status']==2){
                        $_SESSION['login'] = 'true';
                        $_SESSION['member_id'] = $getid['member_id'];
                        $_SESSION['studentid'] = $getid['student_id'];
                        header('location:hometest.php');

                    }elseif($getid['account_status']==1){
                        $_SESSION['login'] = 'maybe';
                        $_SESSION['member_id'] = $getid['member_id'];
                        $_SESSION['studentid'] = $getid['student_id'];
                        header('location:fill.php');

                    }
                }
            }

【问题讨论】:

  • mysql_* 函数已在 PHP 7 中删除。你不应该再使用它们了。
  • 您似乎在混合使用mysql_mysqli_ 函数。
  • mysqli_num_rows($query2)
  • 您也对 SQL 注入持开放态度。不要将用户输入直接传递给 SQL 查询。

标签: php


【解决方案1】:

对于php 5以上的PHP版本我们必须使用mysqli_函数

mysqli_num_rows()

【讨论】:

    猜你喜欢
    • 2014-07-07
    • 2013-12-17
    • 2013-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    • 2013-05-12
    相关资源
    最近更新 更多