-1

I cannot find out what's wrong in this code. Since the query executes and insert also works but the error msg shows:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\kurinchi\kkmalar.php on line 41

$q = intval($_GET['q']);
$availability = isset($_GET['availability']);
$con = mysqli_connect('localhost','root','','kurinchi');

if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}

mysqli_select_db($con,"ajax_demo");
$sql="UPDATE rooms SET availability=(availability-1) WHERE ID = (SELECT ID from (SELECT * from rooms WHERE ID = '".$q."')AS innerResult)" ;
$result = mysqli_query($con,$sql);

if($result === FALSE) { 
    die(mysql_error()); 
}

echo "<table>
<tr>
    <th>ROOM TYPE</th>
    <th>AC TYPE</th>
    <th>PRICE</th>
    <th>AVAILABILITY</th>
    <th>BOOK </th>
</tr>";

while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['room_type'] . "</td>";
    echo "<td>" . $row['ac_type'] . "</td>";
    echo "<td>" . $row['price'] . "</td>";
    echo "<td>" . $row['availability'] . "</td>";
    echo "<td>" . $row['booking_status'] . "</td>";
    echo "</tr>";
}

echo "</table>";
mysqli_close($con);
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • You are UPDATING records here, so mysqli_query only returns `true` on success. You made a query that did not return any records to begin with - because that’s not what UPDATE queries do - yet you still try to _fetch_ records from the result, which makes no sense to begin with. – misorude Oct 26 '18 at 06:49

1 Answers1

-2

Try this after mysqli_query()

if (!$result) {
    printf("Error: %s\n", mysqli_error($con));
    exit();
}
suvojit_007
  • 1,690
  • 2
  • 17
  • 23