mysqli_num_rows出错

时间:2018-04-19 03:39:26

标签: php mysql mysqli

因此我在使用mysqli_num_rows时遇到错误。我从一个提交按钮发送一些信息到另一个PHP页面。一切运行完毕后,假设用新信息更新原始页面并将我发回给该页面。它首次进入页面时工作正常,但在更新发生时失败。此外,当它从更新php代码发送时,url中的id与我在第二次加载时需要的id号匹配。下面你会发现原始的页面php代码,然后更新php代码以及错误信息。

plugin= {"json:target/RunCuke/cucumber.json", "pretty","html:target/RunCuke/cucumber.html", "com.cucumber.listener.ExtentCucumberFormatter"},

displaybook.php

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\Program\displaybook.php on line 8

标题-inc.php

  <?php
  include_once 'header.php';
    if (isset($_GET['id']))
    {
        $isbn = $_GET['id'];
        $sql = "SELECT * FROM books WHERE ISBN = '$isbn';";
        $results = mysqli_query($conn, $sql);
        $resultCheck = mysqli_num_rows($results);
        if ($resultCheck > 0) {
            while($row = mysqli_fetch_assoc($results)){
                echo "<div class = 'book-page'>
                    <h3> ". $row['Title'] . " </h3>
                    <p> ISBN: " . $row['ISBN'] . "</p>
                    <p> Subject: " . $row['Subject'] . "</p>
                    <p> Language: " . $row['Language'] . "</p>
                    <p> Publisher: " . $row['Publisher'] . "</p>
                    <p> Date Published: " . $row['Date_Published'] . "</p>
                    <p> Price: " . $row['Price'] . "</p>
                    <p> " . $row['Summary'] . "</p>";
                    if (isset($_SESSION['user_manager'])) {
                        echo "<p> Quantity: " . $row['Quantity'] ."</p>";
                    }

                    if (isset($_SESSION['email']))
                    {
                        echo "<a href='order.php?id=".$row['ISBN']."'>Order</a><br>";
                    }

                    if (isset($_SESSION['user_manager'])) {
                        echo "<a href='includes/delete-inc.php?id=".$row['ISBN']."'>Delete</a><br>

                            <form class='Update-email' action='includes/title-inc.php' method='POST'>
                                <input type='hidden' name='id' value=" . $row['ISBN'] . ">
                                <input type='text' name='title' placeholder='Title'>
                                <button type='submit' name='submit'>Update Title</button>
                            </form>

2 个答案:

答案 0 :(得分:0)

你的sql查询中有错误,删除额外的分号,之后它应该有效。

$sql = "SELECT * FROM books WHERE ISBN = '$isbn'";

答案 1 :(得分:0)

当您的连接或查询出现问题时会出现此错误

正如我在第一段代码中看到的,您没有在展示簿使用中包含配置文件

include_once' dbh-inc.php';

和第二次使用这样的查询

$sql = "SELECT * FROM books WHERE ISBN = ' ". $isbn . " '";

而不是变量后面的分号

$sql = "SELECT * FROM books WHERE ISBN = '$isbn';";

在查询结尾使用附加分号