mysqli_num_rows()期望参数1为mysqli_result,使用mysqli为布尔值 [英] mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean with mysqli
问题描述
我无法收到警告 sql查询正在工作,并且mysqli_query()返回1,并且每次我的数据库也被更新时.有什么问题吗?
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?
警告:mysqli_num_rows()期望参数1为mysqli_result,第55行的C:\ xampp \ htdocs \ qq \ index.php中给出的布尔值
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\qq\index.php on line 55
的代码是
<?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"];
此代码中有错误:
$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>"
? >
即使我正在删除mysqli_num_rows其显示错误,
even if i am removing mysqli_num_rows its showing error on
推荐答案
根据另一个问题 INSERT
命令将返回一个布尔值(true/false),因此必须使用select命令来获得所需的结果
The INSERT
command will return a boolean(true/false), So you must use select command to get the required result
这篇关于mysqli_num_rows()期望参数1为mysqli_result,使用mysqli为布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!