Hi,
I’m a newbie and doing my class project. I got this script from a book and tried modifying if for use in my project. Once I hit “Submit”, the form doesn’t work. Please help. I’ve attached the script below:
[php]
<?php
$page_title = 'Edit Race Information';
include ('./includes/header.html');
// Check for a valid user ID, through GET or POST.
if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // Accessed through jockeyclub.php
$id = $_GET['id'];
} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form has been submitted.
$id = $_POST['id'];
} else {
echo '
Page Error
This page has been accessed in error.
';
include ('./includes/footer.html');
exit();
}
require_once ('mysqlconnection.php'); // Connect to mysql.
// Check if the form has been submitted.
if (isset($_POST['submitted'])) {
$errors = array(); // Initialize error array.
// Check for a course name.
if (empty($_POST['CourseName'])) {
$errors[] = 'Please enter the Course name.';
} else {
$cn = escape_data($_POST['CourseName']);
}
// Check for a race name.
if (empty($_POST['RaceName'])) {
$errors[] = 'Please enter the Race name.';
} else {
$rn = escape_data($_POST['RaceName']);
}
// Check for race sponsor.
if (empty($_POST['RaceSponsor'])) {
$errors[] = 'Please enter the Race sponsor.';
} else {
$rs = escape_data($_POST['RaceSponsor']);
}
if (empty($errors)) { // If everything's OK.
// Test for unique race name.
$query = "SELECT ID FROM jc_race WHERE RaceName='$rn' AND ID != $id";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0) {
// Make the query.
$query = "UPDATE jc_race SET CourseName='$cn', RaceName='$rn', RaceSponsor='$rs' WHERE ID=$id";
$result = @mysql_query ($query); // Run the query.
if (mysql_affected_rows() == 1) { // If it ran OK.
// Print a message.
echo '
Edit Race Information
The user has been edited.
';
} else { // If it did not run OK.
echo '
System Error
The user could not be edited due to a system error. We apologize for any inconvenience.
'; // Public message.
echo '
' . mysql_error() . '
Query: ' . $query . '
'; // Debugging message.
include ('./includes/footer.html');
exit();
}
} else { // Already registered.
echo '
Error!
The email address has already been registered.
';
}
} else { // Report the errors.
echo '
Error!
The following error(s) occurred:
';
foreach ($errors as $msg) { // Print each error.
echo " - $msg
n";
}
echo '
Please try again.
';
} // End of if (empty($errors)) IF.
} // End of submit conditional.
// Always show the form.
// Retrieve the user's information.
$query = "SELECT CourseName, MeetingDate, MeetingStartTime, RaceName,
RaceTime, RaceSponsor, RacePrizeMoney, RaceGoing, ID
FROM jc_race WHERE ID=$id";
$result = @mysql_query ($query); // Run the query.
if (mysql_num_rows($result) == 1) { // Valid user ID, show the form.
// Get the user's information.
$row = mysql_fetch_array ($result, MYSQL_NUM);
// Create the form.
echo '
Edit Race Information
Course Name:
Race Name:
Race Sponsor:
';
} else { // Not a valid user ID.
echo '
Page Error
This page has been accessed in error.
';
}
mysql_close(); // Close the database connection.
include ('./includes/footer.html');
?>
[/php]
ADMIN EDIT: Added [php] code tags for readability. Please refer to http://phphelp.com/guidelines.php for posting guidelines.