0

我正在尝试使用删除和编辑用户的最终选项来查看当前用户。$dbc 在我的 header.html 文件中的另一个文件中。我收到的唯一不包括页眉/页脚的输出是:警告:mysqli_fetch_array() 期望参数 1 是 mysqli_result,在 C:\xampp\htdocs\Kyle_Site\Programming Rite\controle\view_users.php 中给出的布尔值在线76 编辑 删除 姓 名 注册日期

警告:mysqli_free_result() 期望参数 1 为 mysqli_result,布尔值在 C:\xampp\htdocs\Kyle_Site\Programming Rite\controle\view_users.php 第 89 行给出

<?php # Script 10.5 - #5
// This script retrieves all the records from the users table.
// This new version allows the results to be sorted in different ways.

$page_title = 'View the Current Users';
include ('header.html');
echo '<h1>Registered Users</h1>';



// Number of records to show per page:
$display = 5;

   // Determine how many pages there are...
if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Already been determined.
    $pages = $_GET['p'];
} else { // Need to determine.
    // Count the number of records:
     $q = "SELECT COUNT(user_id) FROM `kb2360716_entity_users`";
    $r = mysqli_query ($dbc, $q);
    $row = mysqli_fetch_array ($r, MYSQLI_NUM);
    $records = $row[0];
    // Calculate the number of pages...
    if ($records > $display) { // More than 1 page.
        $pages = ceil ($records/$display);
    } else {
        $pages = 1;
     }
} // End of p IF.

// Determine where in the database to start returning results...
if (isset($_GET['s']) && is_numeric($_GET['s'])) {
    $start = $_GET['s'];
 } else {
$start = 0;
}

// Determine the sort...
// Default is by registration date.
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'rd';

// Determine the sorting order:
switch ($sort) {
    case 'ln':
         $order_by = 'last_name ASC';
         break;
    case 'fn':
        $order_by = 'first_name ASC';
        break;
    case 'rd':
        $order_by = 'registration_date ASC';
        break;
    default:
        $order_by = 'registration_date ASC';
        $sort = 'rd';
        break;
}

// Define the query:"SELECT last_name, first_name, DATE_FORMAT(registration_date, '%M        %d, %Y') AS dr, user_id FROM `kb2360716_entity_users` ORDER BY $order_by LIMIT $start,   $display";        
$q = "SELECT `id`,`username`,`firstname`,`lastname`,`email` FROM `kb2360716_entity_users` ORDER BY `id` ASC";
$r = mysqli_query ($dbc, $q); // Run the query.

// Table header:
echo '<table align="center" cellspacing="0" cellpadding="5" width="75%">
<tr>
    <td align="left"><b>Edit</b></td>
    <td align="left"><b>Delete</b></td>
    <td align="left"><b><a href="view_users.php?sort=ln">Last Name</a></b></td>
    <td align="left"><b><a href="view_users.php?sort=fn">First Name</a></b></td>
    <td align="left"><b><a href="view_users.php?sort=rd">Date Registered</a></b>  </td>
</tr>
';

// Fetch and print all the records....
$bg = '#eeeeee'; 
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
    $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
         echo '<tr bgcolor="' . $bg . '">
         <td align="left"><a href="edit_user.php?id=' . $row['user_id'] .   '">Edit</a></td>
        <td align="left"><a href="delete_user.php?id=' . $row['user_id'] . '">Delete</a></td>
        <td align="left">' . $row['last_name'] . '</td>
        <td align="left">' . $row['first_name'] . '</td>
        <td align="left">' . $row['dr'] . '</td>
    </tr>
    ';
 } // End of WHILE loop.

echo '</table>';
mysqli_free_result ($r);
mysqli_close($dbc);

// Make the links to other pages, if necessary.
if ($pages > 1) {

     echo '<br /><p>';
     $current_page = ($start/$display) + 1;

     // If it's not the first page, make a Previous button:
     if ($current_page != 1) {
        echo '<a href="view_users.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '">Previous</a> ';
    }

    // Make all the numbered pages:
    for ($i = 1; $i <= $pages; $i++) {
        if ($i != $current_page) {
            echo '<a href="view_users.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> ';
        } else {
            echo $i . ' ';
         }
    } // End of FOR loop.

    // If it's not the last page, make a Next button:
    if ($current_page != $pages) {
            echo '<a href="view_users.php?s=' . ($start + $display) . '&p=' . $pages . '&sort=' . $sort . '">Next</a>';
    }

     echo '</p>'; // Close the paragraph.

} // End of links section.
echo mysqli_error();
include ('footer.html');
?>

这是我的 header.html 的顶部:

<?php
require 'connect.inc.php';
require 'core.inc.php';
if (!loggedin()) 
    {
        header("Location: index2.php");
        exit;
    }
?>

这是我的 connect.inc.php:

<?php
$mysql_host='209.129.8.3';
$mysql_user='47278';

$conn_error='Could not connect';
$mysql_db='47278';

$dbc = @mysqli_connect ($mysql_host, $mysql_user, $mysql_pass);
if(!@mysql_connect($mysql_host, $mysql_user, $mysql_pass) || !@mysql_select_db($mysql_db)){
die($conn_error);
}

?>

我进行了更改并删除了 3 个@,现在我有一个新错误以及两个旧的警告:mysqli_fetch_array() 期望参数 1 是 mysqli_result,在 C:\xampp\htdocs\Kyle_Site\Programming Rite 中给出的布尔值\controle\view_users.php 第 21 行

警告:mysqli_fetch_array() 期望参数 1 为 mysqli_result,布尔值在 C:\xampp\htdocs\Kyle_Site\Programming Rite\controle\view_users.php 第 76 行给出

警告:mysqli_free_result() 期望参数 1 为 mysqli_result,布尔值在 C:\xampp\htdocs\Kyle_Site\Programming Rite\controle\view_users.php 第 89 行给出

4

1 回答 1

-1

the problem is here:

$r = @mysqli_query ($dbc, $q);

remve the @ infront of it and you will see the mySQL error that gives you. This way you suppressed the error and it results as FALSE, which is why the next lines fails after.

于 2012-12-09T07:45:13.443 回答