153 lines
4.9 KiB
PHP
153 lines
4.9 KiB
PHP
|
<?php # Script 9.5 - register.php #2
|
||
|
// This script performs an INSERT query to add a record to the users table.
|
||
|
|
||
|
$page_title = 'New Lecturer';
|
||
|
include ('includes/header.html');
|
||
|
|
||
|
// Check for form submission:
|
||
|
|
||
|
// echo $_SERVER['REQUEST_METHOD'];
|
||
|
|
||
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||
|
|
||
|
//echo '1';
|
||
|
|
||
|
require('mysqli_connect.php'); // Connect to the db.
|
||
|
|
||
|
//echo '2';
|
||
|
|
||
|
$errors = array(); // Initialize an error array.
|
||
|
|
||
|
//echo '3';
|
||
|
|
||
|
// Check for a first name:
|
||
|
if (empty($_POST['first_name'])) {
|
||
|
echo 'You forgot to enter your first name.';
|
||
|
$errors[] = 'You forgot to enter your first name.';
|
||
|
} else {
|
||
|
$fn = mysqli_real_escape_string($dbc, trim($_POST['first_name']));
|
||
|
}
|
||
|
|
||
|
// Check for a last name:
|
||
|
if (empty($_POST['last_name'])) {
|
||
|
$errors[] = 'You forgot to enter your last name.';
|
||
|
} else {
|
||
|
$ln = mysqli_real_escape_string($dbc, trim($_POST['last_name']));
|
||
|
}
|
||
|
|
||
|
// Check for an email address:
|
||
|
if (empty($_POST['email'])) {
|
||
|
$errors[] = 'You forgot to enter your email address.';
|
||
|
} else {
|
||
|
$e = mysqli_real_escape_string($dbc, trim($_POST['email']));
|
||
|
}
|
||
|
|
||
|
|
||
|
if (empty($_POST['gender'])) {
|
||
|
$errors[] = 'You forgot to enter your gender.';
|
||
|
} else {
|
||
|
$g = mysqli_real_escape_string($dbc, trim($_POST['gender']));
|
||
|
}
|
||
|
|
||
|
if (empty($_POST['ssn'])) {
|
||
|
$errors[] = 'You forgot to enter your ssn.';
|
||
|
} else {
|
||
|
$s = mysqli_real_escape_string($dbc, trim($_POST['ssn']));
|
||
|
}
|
||
|
|
||
|
if (empty($errors)) { // If everything's OK.
|
||
|
|
||
|
// Register the lecturer in the database...
|
||
|
|
||
|
// Make the query:
|
||
|
$q = "INSERT INTO Lecturers (LecLastName, LecFirstName, LecEmail, Gender, SSN) VALUES ('$ln', '$fn', '$e', '$g', '$s')";
|
||
|
$r = @mysqli_query ($dbc, $q); // Run the query.
|
||
|
if ($r) { // If it ran OK.
|
||
|
|
||
|
// Print a message:
|
||
|
echo '<h1>Thank you!</h1>
|
||
|
<p>You are now in the database.</p><p><br /></p>';
|
||
|
|
||
|
} else { // If it did not run OK.
|
||
|
|
||
|
// Public message:
|
||
|
echo '<h1>System Error</h1>
|
||
|
<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</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.
|
||
|
|
||
|
} // End of the main Submit conditional.
|
||
|
?>
|
||
|
|
||
|
<form class="form-horizontal" action="show_roster.php" method="post">
|
||
|
<fieldset>
|
||
|
<legend>Register</legend>
|
||
|
|
||
|
<div class="form-group">
|
||
|
<label for="first_name" class="col-lg-2 control-label">First Name:</label>
|
||
|
<div class="col-lg-10">
|
||
|
<input class="form-control" placeholder="First Name" autocomplete="off" name="first_name" id="first_name" size="15" maxlength="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" />
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div class="form-group">
|
||
|
<label for="last_name" class="col-lg-2 control-label">Last Name:</label>
|
||
|
<div class="col-lg-10">
|
||
|
<input class="form-control" placeholder="Last Name" autocomplete="off" type="text" name="last_name" id="last_name" size="15" maxlength="40" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" />
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div class="form-group">
|
||
|
<label for="email" class="col-lg-2 control-label">Email Address:</label>
|
||
|
<div class="col-lg-10">
|
||
|
<input class="form-control" placeholder="Email Address" autocomplete="off" type="text" name="email" id="email" size="20" maxlength="60" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" />
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div class="form-group">
|
||
|
<label for="gender" class="col-lg-2 control-label">Gender:</label>
|
||
|
<div class="col-lg-10">
|
||
|
<input class="form-control" placeholder="Gender" autocomplete="off" type="text" name="gender" id="gender" size="10" maxlength="20" value="<?php if (isset($_POST['gender'])) echo $_POST['gender']; ?>" />
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div class="form-group">
|
||
|
<label for="ssn" class="col-lg-2 control-label">SSN:</label>
|
||
|
<div class="col-lg-10">
|
||
|
<input class="form-control" placeholder="SSN" autocomplete="off" type="text" name="ssn" id="ssn" size="10" maxlength="20" value="<?php if (isset($_POST['ssn'])) echo $_POST['ssn']; ?>" />
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<!-- submit button -->
|
||
|
<div class="form-group">
|
||
|
<div class="col-lg-10 col-lg-offset-2">
|
||
|
<button type="submit" name="submit" class="btn btn-primary">Register</button>
|
||
|
</div>
|
||
|
</div>
|
||
|
</fieldset>
|
||
|
</form>
|
||
|
|
||
|
<?php include ('includes/footer.html'); ?>
|