-2

不显示任何信息。出现错误,我真的不知道为什么?谢谢。

    <?php

    $mysqli = new mysqli("localhost", "root", "", "insuredcars");
     if ($_POST['formcar'] == '1' || $_POST['formage'] == '18' ||  $_POST['formNCD'] ==          '0' || $_POST['formPoints'] == '0' )
    $query = $mysqli->query("SELECT * FROM insurance WHERE insuranceid = '1'");
while($row = mysql_fetch_array($result))
 {
 echo "<tr>";
 echo "<td>" . $row['insuranceprice'] . "</td>";
 echo "</tr>";
  }
 echo "</table>";

 mysql_close($con);

 ?>

我得到的错误:注意:未定义的变量:导致 C:在第 8 行

警告:mysql_fetch_row() 期望参数 1 是资源,在第 8 行的 C:\xampp\htdocs\search.php 中给出 null

注意:未定义的变量:C 中的 con:第 16 行

警告:mysql_close() 期望参数 1 是资源,在 C: 第 16 行给出 null

4

2 回答 2

0

mysqli_fetch_row正如函数名所说,只获取一行。

$mysqli = new mysqli("localhost", "root", "", "insuredcars");
if ($_POST['formcar'] == '1' || $_POST['formage'] == '18' || $_POST['formNCD'] == '0' || $_POST['formPoints'] == '0') {    
    $query = $mysqli->query("SELECT * FROM insurance WHERE insuranceid = '1'");
    while ($row = mysqli_fetch_assoc($query)) {
        echo "<tr>";
        echo "<td>" . $row['insuranceprice'] . "</td>";
        echo "</tr>";
    }
    echo "</table>";
}

mysql_close($con);
于 2013-04-22T00:38:53.997 回答
0

尝试阅读有关 usingmysqli_fetch_row而不是的其他答案mysql_fetch_row,但我认为您需要注意的是这一行:

$query = $mysqli->query("SELECT * FROM insurance WHERE insuranceid = '1'");

您将结果存储到$query变量中,但是当您循环时:

while($row = mysql_fetch_array($result))

您尝试获取$result未在此处声明的变量。

于 2013-04-22T00:52:25.007 回答