Jump to content
Larry Ullman's Book Forums

Sending Values To A Script


Recommended Posts

I am using material from Chapter 10 to design scripts for recording attendance data for persons listed in a Household table in an additiona table called Attendance.

I have two scripts.  The first is "view_households.php" and is listed here:

<?php # Script 10.1 - view_households.php #3
// This script retrieves all the records from the household table.
// This new version links to edit and delete pages.
 
$page_title = 'View the Current Households';
include ('includes/header.html');
echo '<h1>Registered Households</h1>';
 
require_once ('includes/mysqli_connect.php');
 
// Define the query:
$q = "SELECT last_name,first_name,hh_id FROM Households ORDER BY last_name ASC";
$r = @mysqli_query ($dbc, $q);
 
// Count the number of returned rows:
$num = mysqli_num_rows($r);
 
if ($num > 0) { // If it ran OK, display the records.
 
// Print how many Households there are:
echo "<p>There are currently $num registered households.</p>\n";
 
// Table header:
echo '<table align="center" cellspacing="3" cellpadding="3" width="75%">
<tr>
<td align="left"><b>Register_Attend</b></td>
<td align="left"><b>Delete</b></td>
<td align="left"><b>Last Name</b></td>
<td align="left"><b>First Name</b></td>
                <td align="left"><b>hh_id</b></td>
</tr>
';
 
// Fetch and print all the records:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
echo '<tr>
<td align="left"><a href="register_attendance.php?id=' . $row['hh_id'] . '">Register_Attend</a></td>
<td align="left"><a href="delete_user.php?id=' . $row['hh_id'] . '">Delete</a></td>
<td align="left">' . $row['last_name'] . '</td>
<td align="left">' . $row['first_name'] . '</td>
                        <td align="left">' . $row['hh_id'] . '</td>
</tr>
';
}
 
echo '</table>';
mysqli_free_result ($r);
 
} else { // If no records were returned.
echo '<p class="error">There are currently no registered households.</p>';
}
 
mysqli_close($dbc);
 
include ('includes/footer.html');
?>
 
Records from Household are displayed from this script.
If one clicks the "register_attendance" from the display, a spript "register_attendance.php is called and the records id is passed through the URL.
 
Here is the script for "register_attendance.php":
<?php # Script 9.5 - register_attendance.php #2
// This script performs an INSERT query to add a record to the users table.
 
$page_title = 'Register Attendance';
 
// Check for a valid household ID, through GET or POST:
if ( (isset($GET['id'])) && (is_numeric ($_GET['id'])) ) { // From view_households.php
    $id = $GET['id'];
        echo '<p>We have the value of $id </p>';
} 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_once ('includes/mysqli_connect.php');
 
 
if (empty($errors)) { // If everything's OK.
 
// Register the user in the database...
                echo <p>Now on line 11. </p>;
// Make the query:
$q = "INSERT INTO Attendance (dateofattendance,fkhh_id,attendees,event,note)
                VALUES ('2013-11-24','$id','NULL','NULL','NULL');"
$r = @mysqli_query ($dbc, $q); // Run the query.
if ($r) { // If it ran OK.
                         
echo '<p> Attendance is recorded on line 18.</p><p><br /></p>';
 
} else { // If it did not run OK.
 
// Public message:
echo '<h1>System Error</h1>
<p class="error">You could not record attendance.</p>';
 
// Debugging message:
echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
 
} // End of if ($r) IF.
 
mysqli_close($dbc); // Close the database connection.
 
// Include the footer and quit the script:
include ('includes/footer.html');
exit();
 
} else { // Report the errors.
 
echo '<h1>Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) { // Print each error.
echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p><p><br /></p>';
 
} // End of if (empty($errors)) IF.
 
mysqli_close($dbc); // Close the database connection.
 
?>
<?php include ('includes/footer.html'); ?>
======================
When I click a record displayed from view_households.php, I get a blank screen.
In fact, if I attempt to view the "scource" for the page, that is blank also.
 
Can anyone identify what I am doing wrong?
One can test this for yourself by putting the following in your browser:
"learningpreferences.org/view_households.php"
 
Thank you for your assistance.  Again, I am using the contents of Chapter 10 as my guide.
 
Wes Smith
 

 

Link to comment
Share on other sites

WOW!  Thanks Larry!  You will never know how helpful a comment like "be sure that display_errors is enabled" is to a newbie like me!

It took me a while to find how to do that.  My site is hosted by awardspace.net. He it was not too difficult to find how to edit php.nin.

 

After  several attempts to run, I was able to identify my mistake.  Thank you!

 

I hope that within a few days I will be running my website with its MySQL database to be used by schools and churches.

 

Again, that you for both your assistance and FOR YOUR BOOK!

 

Wes Smith

Link to comment
Share on other sites

 Share

×
×
  • Create New...