PHP错误 - 我的错误是什么意思?

时间:2016-02-07 04:14:16

标签: php

点击view_users.php页面上的删除链接后,我收到此错误。我认为错误发生在delete_users.php页面上,但是当我使用你可以从他的网站下载的数据文件版本时,我仍然会得到同样的错误。

这是错误:

警告:mysqli_num_rows()要求参数1为mysqli_result,/ var / www / PHP中为boolean,动态网站为MySQL /第38行为delete_user.php

<?php # Script 10.2 - delete_user.php
// This page is for deleting a user record.
// This page is accessed through view_users.php.

$page_title = 'Delete a User';
include ('includes/header.html');
echo '<h1>Delete a User</h1>';

// Check for a valid user ID, through GET or POST:
if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // From view_users.php
    $id = $_GET['id'];
} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form submission.
    $id = $_POST['id'];
} else { // No valid ID, kill the script.
    echo '<p class="error">This page has been accessed in error.</p>';
    include ('includes/footer.html'); 
    exit();
}

require ('mysqli_connect.php');

// Check if the form has been submitted:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    if ($_POST['sure'] == 'Yes') { // Delete the record.

        // Make the query:
        $q = "DELETE FROM users WHERE user_id=$id LIMIT 1";     
        $r = @mysqli_query ($dbc, $q);
        if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.

            // Print a message:
            echo '<p>The user has been deleted.</p>';   

        } else { // If the query did not run OK.
            echo '<p class="error">The user could not be deleted due to a system error.</p>'; // Public message.
            echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $q .     '</p>'; // Debugging message.
        }

    } else { // No confirmation of deletion.
        echo '<p>The user has NOT been deleted.</p>';   
    }

} else { // Show the form.

    // Retrieve the user's information:
    $q = "SELECT CONCAT(last_name, ', ', first_name) FROM users WHERE user_id=$id";
    $r = @mysqli_query ($dbc, $q);

    if (mysqli_num_rows($r) == 1) { // Valid user ID, show the form.

        // Get the user's information:
        $row = mysqli_fetch_array ($r, MYSQLI_NUM);

        // Display the record being deleted:
        echo "<h3>Name: $row[0]</h3>
        Are you sure you want to delete this user?";

        // Create the form:
        echo '<form action="delete_user.php" method="post">
    <input type="radio" name="sure" value="Yes" /> Yes 
    <input type="radio" name="sure" value="No" checked="checked" /> No
    <input type="submit" name="submit" value="Submit" />
    <input type="hidden" name="id" value="' . $id . '" />
    </form>';

    } else { // Not a valid user ID.
        echo '<p class="error">This page has been accessed in error.    </p>';
    }

} // End of the main submission conditional.

mysqli_close($dbc);

include ('includes/footer.html');
?>

2 个答案:

答案 0 :(得分:1)

Sessions

您应该检查$ r是否为假并找出出错的地方

ManyToMany

答案 1 :(得分:1)

尝试检查数据库连接是否有任何问题。因此,看看$dbc是否会引发任何错误,可能会导致mysqli_query()出现问题。对于调试sakes,删除mysqli_query()前面的错误控制操作符。

此外,查看您尝试运行的查询(SELECT CONCAT(last_name, ', ', first_name) FROM users WHERE user_id=$id)是否会引发任何错误。作为快速提示,不要对查询使用字符串插值,尝试将变量绑定到预准备语句作为参数。