PHP edit.PHP脚本中的MySQL错误

PHP edit.PHP脚本中的MySQL错误,php,mysql,mysqli,Php,Mysql,Mysqli,我为数据库创建的edit.PHP脚本在PHP中出现警告错误。当我单击并转到编辑屏幕时,它向我发出一个错误:警告:mysqli_num_rows()期望参数1是mysqli_result,布尔值在第34行的/./edit.php中给出。第34行代码读取if(mysqli\u num\u rows($sql)>0)如果有人能给我一个解决这个错误的方法,我将不胜感激 代码如下: <?php require_once("includes/connection.inc.php"); ?> &

我为数据库创建的edit.PHP脚本在PHP中出现警告错误。当我单击并转到编辑屏幕时,它向我发出一个错误:警告:mysqli_num_rows()期望参数1是mysqli_result,布尔值在第34行的/./edit.php中给出。第34行代码读取
if(mysqli\u num\u rows($sql)>0)
如果有人能给我一个解决这个错误的方法,我将不胜感激

代码如下:

<?php
require_once("includes/connection.inc.php");
?>

<!DOCTYPE html>
<html lang="en">
<head>

    <!-- Bootstrap -->
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>
    <h1>Edit Record</h1>
    <p>Edit the tree!</p>
    <?php $id = $_GET["id"]; ?>
    <form method="POST" role="form" action="leaferie.php?flag=1&id=<?php echo $id; ?>">
    <?php $dbc = dbConnect('read'); ?>

        <?php
        $sql = mysqli_query($dbc, "SELECT * FROM trees WHERE id = $id");
            if (mysqli_num_rows($sql) > 0)
                { 
                    $row = mysqli_fetch_array($sql) ?>
                    <div class="form-group">
                        <label for="treeName">Tree Name</label>
                        <input name="tree_name" value="<?php echo $row["tree_name"] ?>" type="text" class="form-control" id="treeName">
                    </div>
                    <div class="form-group">
                        <label for="scientificName">Scientific Name</label>
                        <input name="scientific_name" value="<?php echo $row["scientific_name"] ?>" type="text" class="form-control" id="scientificName">
                    </div>
                    <div class="form-group">
                        <label for="plantType">Plant Type</label>
                        <input name="plant_type" value="<?php echo $row["plant_type"] ?>" type="text" class="form-control" id="plantType">
                    </div>
                    <div class="form-group">
                        <label for="leaf">Leaf</label>
                        <input name="leaf" value="<?php echo $row["leaf"] ?>" type="text" class="form-control" id="leaf">
                    </div>
                    <div class="form-group">
                        <label for="flower">Flower</label>
                        <input name="flower" value="<?php echo $row["flower"] ?>" type="text" class="form-control" id="flower">
                    </div>
                    <div class="form-group">
                        <label for="fruit">Fruit</label>
                        <input name="fruit" value="<?php echo $row["fruit"] ?>" type="text" class="form-control" id="fruit">
                    </div>
                    <div class="form-group">
                        <label for="hardiness">Hardiness</label>
                        <input name="hardiness" value="<?php echo $row["hardiness"] ?>" type="text" class="form-control" id="hardiness">
                    </div>
                    <div class="form-group">
                        <label for="culture">Culture</label>
                        <input name="culture" value="<?php echo $row["culture"] ?>" type="text" class="form-control" id="culture">
                    </div>
                    <div class="form-group">
                        <label for="size">Size</label>
                        <input name="size" value="<?php echo $row["size"] ?>" type="text" class="form-control" id="size">
                    </div>
                    <div class="form-group">
                        <label for="uses">Uses</label>
                        <input name="uses" value="<?php echo $row["uses"] ?>" type="text" class="form-control" id="uses">
                    </div>
                    <div class="form-group">
                        <label for="notes">Notes</label>
                        <input name="notes" value="<?php echo $row["notes"] ?>" type="text" class="form-control" id="notes">
                    </div>
                <?php 
                } 
                ?>
    <a href="leaferie.php?flag=2">View Records</a>
    <button class="btn btn-primary" name="submit" type="submit">Submit</button>
    </form>

</body>

编辑记录
编辑树


很明显,这是mysqli没有返回任何有效内容的问题。。。因此,检查错误,所有错误都应该变得清晰。

在假设查询有效并尝试确定返回的行数之前,您需要处理来自
mysqli_query()
false
结果。正如Mike Brandt所说,您的查询失败了,请找出原因。
if ($sql == FALSE) {echo mysqli_error(); exit;}
if (mysqli_num_rows($sql) > 0) {//do your thing
}