-2

Isn't displaying any information. Getting errors and i'm really not sure why? Thanks.

    <?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);

 ?>

The errors im getting: Notice: Undefined variable: result in C: on line 8

Warning: mysql_fetch_row() expects parameter 1 to be resource, null given in C:\xampp\htdocs\search.php on line 8

Notice: Undefined variable: con in C: on line 16

Warning: mysql_close() expects parameter 1 to be resource, null given in C: on line 16

  • What error are you seeing? – tom Apr 22 '13 at 00:35
  • 2
    You're confusinf `mysqli_fetch_row` with `mysql_fetch_array`. Stick with MySQLi ! – Nir Alfasi Apr 22 '13 at 00:36
  • I don't know why that is not displaying any data... I mean, c'mon. We don't even know your errors! – Daryl Gill Apr 22 '13 at 00:36
  • In addition to confusing them, you're using `mysqli_fetch_row()` to attempt to grab the entire result set. As the function name implies, it just fetches ONE row. Beyond that, you are mixing functional and object-oriented mysqli. It would be good to stick with one or the other. You need a good trip through the documentation, paying careful attention to the examples. http://php.net/manual/en/mysqli-result.fetch-object.php – Patrick Moore Apr 22 '13 at 00:38
  • possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Jocelyn Apr 22 '13 at 01:03

2 Answers2

0

mysqli_fetch_row fetches just one row as the function name says.

$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);
TheNiceGuy
  • 3,462
  • 8
  • 34
  • 64
0

Try to read other answer about using mysqli_fetch_row rather than mysql_fetch_row, but what I think you need to be careful is in this line:

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

You store the result into $query variable, but when you loop:

while($row = mysql_fetch_array($result))

You try to fetch $result variable, which is not declared here.

Ruly
  • 360
  • 1
  • 8