Asked  7 Months ago    Answers:  2   Viewed   77 times

I am not able to get the warning the sql query is working and mysqli_query() returns 1 and each time my database is also being updated . What is the problem?

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:xampphtdocsqqindex.php on line 55

of the code which is

<?php
 try{
  $host="localhost";

 $user="deb";
 $password="12345";
 $database="1";
 $conn=mysqli_connect($host,$user,$password,$database);
 if (mysqli_connect_errno())
 {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
 }
 echo "connected succesfully";
   }catch(Exception $e){
 echo $e->getMessage();
 }
 $select=mysqli_select_db($conn,$database);
 if($select)
  {
  echo "yipee";
  }

echo "<table>
<thead>
<tr>
    <th>Id</th>
    <th>Value</th>
    <th>Threshold Value</th>
    <th>Chances of Fire</th>
</tr>
</thead>";
$val=$_GET["val"];

the error is in this code:

$tval=$_GET["tval"];
 if ($val<$tval) {
 $res="less ";
 }
else{$res="exreme ";}
$sql1="INSERT INTO sensor (val,tval,result) VALUES 
('".$val."','".$tval."','".$res."')"; 
 $que=mysqli_query($conn,$sql1);
 if($que)
  {
  if(mysqli_num_rows($que))
   {
    while ($data=mysqli_fetch_array($que))
     {
    echo "<tr>";
    echo "<td>".$data['id']."</td><td>".$data['val']."/td> 
       <td>".$data['tval']."</td><td>".$data['result']."</td>";
    echo"</tr>";
     }
   }

   else{
      echo "nooooooo";
        } 
      }     
      echo"</table>"
        ? >

even if i am removing mysqli_num_rows its showing error on

 Answers

58

According to another question here :

The INSERT command will return a boolean(true/false), So you must use select command to get the required result

Friday, May 28, 2021
 
Muazam
answered 7 Months ago
72

You're combining procedural and object oriented approaches, when you only want object oriented. Change

$num=mysqli_num_rows($WHAT);

to

$num = $stmt->num_rows();
Wednesday, March 31, 2021
 
Yarin
answered 9 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share