SQL 数据提取错误


sql data fetch bug

我有两页。在第一页中,如果用户单击按钮,那么他将获得带有id列的相关数据

<form action='edit.php?id=$id' method='post' name='edit_btn'> 
<button type='submit' class='w3-btn w3-red w3-round-xlarge'>Proceed </button> 
</form>   
        $con=mysqli_connect("localhost","root","","student_result_info_db");if (mysqli_connect_errno()){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); }else{ 
          if(isset($_GET['edit_btn'])){
              echo "<div class='w3-container w3-red'> <h1>>Error Found!</h1> <h4>OK You Did Hit The EDIT Button</h4> </div> <br/>";
          }else{  
             $get_selected_id = $_GET['id'];
             echo $get_selected_id;
             $res = "SELECT * FROM school_result";

                 while ($row = mysql_fetch_array($res)){
                     echo "$row[id]. $row[first_name] <br/>";
                     echo "$row[id]. $row[last_name] <br/>";
                 } 
          }
    }

它显示以下错误

致命错误:调用未定义的函数 mysql_fetch_array()

改用mysqli_fetch_array,以及mysqli_query来获取mysqli_result对象:

$qresult = mysqli_query($con, $res);
while ($row = mysqli_fetch_array($qresult)){

您需要使用它有两个原因:

  1. 您使用 mysqli_connect 打开了数据库,因此需要使用mysqli函数。

  2. mysql函数在 PHP 7 中删除。

使用 mysqli 函数而不是像 mysql 一样

mysqli_query($con, $res);