<?php
// This is the registration page for the site.
// Set the page title and include the HTML header.
$page_title = 'Books';
include('includes/header_customer.html');
if (isset($_POST['submit'])) { // Handle the form.
// Register the user in the database.
require_once ('./mysql_connect.php'); // Connect to the db.
// Create a function for escaping the data.
function escape_data ($data) {
global $dbc; // Need the connection.
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string($data, $dbc);
} // End of function.
$message = NULL; // Create an empty new variable.
// Check for a category id.
if (empty($_POST['category_id'])) {
$ci = FALSE;
$message .= '<p>You forgot to enter category id!</p>';
} else {
$ci = escape_data($_POST['category_id']);
}
// Check for a author's first name.
if (empty($_POST['author_first'])) {
$af = FALSE;
$message .= '<p>You forgot to enter author first name!</p>';
} else {
$af = escape_data($_POST['author_first']);
}
// Check for the author's middle name.
if (empty($_POST['author_middle'])) {
$ae = FALSE;
$message .= '<p>You forgot to enter middle name!</p>';
$ae = escape_data($_POST['author_middle']);
}
// Check for the author's last name.
if (empty($_POST['author_last'])) {
$al = FALSE;
$message .= '<p>You forgot to enter last name!</p>';
} else {
$al = escape_data($_POST['author_last']);
}
if ( $ci && $af && $ae && $al ) { // If everything's OK.
// Add the book.
$query = "INSERT INTO category (category_id, author_first, author_middle, author_last) VALUES ('$ci, $af, $am, $al, NOW() )";
$result = @mysql_query ($query); // Run the query.
mysql_close(); // Close the database connection.
} else { // If it did not run OK.
$message = '<p>Please try again.</p>';
}
} // End of the main Submit conditional.
// Print the error message if there is one.
if (isset($message)) {
echo '<font color="red">', $message, '</font>';
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>"method="post">
<fieldset><legend>Enter book information in the form below:</legend>
<table>
<tr><td align= left>
<p><b>Category ID:</b></td> <td align= left> <input type="text" name="category_id" size="10" maxlength="10" value="<?php if (isset($POST['category_id'])) echo $POST['category_id']; ?>" /></p>
</td></tr>
<tr><td>
<p><b>Author's First Name:</b></td> <td align= left> <input type="text" name="author_first" size="10" maxlength="10" value="<?php if (isset($POST['author_first'])) echo $POST['author_first']; ?>" /></p>
</td></tr>
<tr><td>
<p><b>Author's Middle Name:</b></td> <td align= left> <input type="text" name="author_middle" size="10" maxlength="10" value="<?php if (isset($POST['author_middle'])) echo $POST['author_middle']; ?>" /></p>
</td></tr>
<tr><td>
<p><b>Author's Last Name:</b></td> <td align= left> <input type="text" name="author_last" size="10" maxlength="10" value="<?php if (isset($POST['author_last'])) echo $POST['author_last']; ?>" /></p>
</td></td></table>
</fieldset>
<div align="center"><input type="submit" name="submit" value="SUBMIT" /></div>
</form><!-- End of Form -->
<?php
include ('includes/footer_home.html');
?>