Jump to content
Larry Ullman's Book Forums

Chapter 10 Edit A Record: View.... --> Edit


Recommended Posts

I used script 10.5 as a model for view_households.php but get he following error message:

------------

warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/content/00/10035700/html/pumc/edit_household.php on line 97

This page has been accessed in error without valid hh_id

--------------------

<?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.
session_start();// access session variables.
$page_title = 'View the Current Households';
include ('includes/header.html');
echo '<h1>Registered Users</h1>';
 
require ('includes/mysqli_connect.php');
 
// Number of records to show per page:
$display = 10;
 
// 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(hh_id) FROM Households";
$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 last name.
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'ln';
 
// Determine the sorting order:
switch ($sort) {
case 'ln':
$order_by = 'LastName ASC';
break;
case 'fn':
$order_by = 'FirstName ASC';
break;
default:
$order_by = 'LastName ASC';
$sort = 'ln';
break;
}
 
// Define the query:
$q = "SELECT LastName, FirstName, hh_id FROM Households ORDER BY $order_by LIMIT $start, $display";
$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_household.php?id=' . $row['hh_id'] . '">Edit</a></td>
<td align="left"><a href="delete_household.php?id=' . $row['hh_id'] . '">Delete</a></td>
<td align="left">' . $row['LastName'] . '</td>
<td align="left">' . $row['FirstName'] . '</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_Households.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_Households.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_households.php?s=' . ($start + $display) . '&p=' . $pages . '&sort=' . $sort . '">Next</a>';
}
 
echo '</p>'; // Close the paragraph.
 
} // End of links section.
 
include ('includes/footer.html');
?>
 
-----------------------
When I run "view_households.php" I see the table of records.
When I click the EDIT link it displays "edit_households.php" with ....php?id....
But then I get the error that no valid hh_id is available.
 
I would appreciate any help.
I have been struggling with this for days.
 
Thanks in advance.
Wes Smith
 
Link to comment
Share on other sites

Let me add this......

 

When I run the script "stylesoflearningnet/view_users.php" things seem to work.

When I run the script "stylesoflearning.net/pumc/view_households.php" I get the error.

 

Using this subfolder on my website may be causing the error??

 

I appreciate any advice.

 

Wes Smith

 

Link to comment
Share on other sites

 Share

×
×
  • Create New...