Hi Guys
This is my first post on these forums. Up until this point I haven't had any problems but now I've hit a bit of a wall..
First off if this has been brought up before my apologise, I did search through the forum but could not find anything about this anywhere else.
I have written script 8.3 out as it was described in the book and tried to run it, but all I am greeted with is a blank page. Even the header has not been loaded. I checked the code a few times and then copied the 8.3 script from the support files but this yielded the same result.
My files are all in the correct folders and I just can't work out why this is happening. index.php loads fine and connect.php as it is named for me connects to the database fine.
Anyone any ideas why this might be happening. I'll post my code just incase theres a problem with it but as I said I also tried copying the code exactly from the support files and that didnt work either.
<?php // Registration Form
$page_title = 'Register';
include ('includes/header.html');
// Check if form has been submitted:
if (isset($_POST['submitted'])) {
$errors = array(); // Initialise and Error Array.
// Check for first name:
if (empty($_POST['first_name'])) {
$errors[] = 'You forgot to enter your first name.';
} else {
$fn = trim($_POST['first_name']);
}
// Check for last name:
if (empty($_POST['last_name'])) {
$errors[] = 'You forgot to enter your last name.';
} else {
$ln = trim($_POST['last_name']);
}
// Check for email
if (empty($_POST['email'])) {
$errors[] = 'You did not enter an email.';
} else {
$e = trim($_POST['email']);
}
// Check for a password and match against confirmed
if (empty($_POST['pass1'])) {
if ($_POST['pass2'] != $_POST['pass1']) {
$errors[] = 'Your passwords do not match.';
} else {
$p = trim($_POST['pass1']);
}
} else {
$errors[] = 'You did not enter a password.';
}
// If there are no errors - Continue
if (empty($errors()) {
// Register the user in the database
require_once ('../connect.php'); // Make the connection
$q = "INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() );
$r = @mysqli_query ($dbc, $q); // Run the query.
// Check to make sure the query ran ok
if ($r) {
// Print a thank you message
echo '<h1>Thank You!</h1> <p>You are now registered. In the future you will be able to login to this site</p>';
} else {
echo '<h1>System Error</h1> <p>You could not be registered because of a system error. We are doing everything we can to resolve it<br />Please try again later</p>'
// Debugging Message:
echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
}
mysqli_close($dbc); // Close the database connection.
// Include the footer and quit script
include ('includes/footer.html');
exit();
} else {
echo '<h1>Error!</h1> <p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) {
echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p><p><br /></p>';
}
}
?>
<h1>Regiister</h1>
<form action="register.php" method="post">
<p>First Name: <input type="text" name="first_name" size="15" maxlength="20" value="<?php if(isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
<p>Last Name: <input type="text" name="last_name" size="15" maxlength="40" value="<?php if(isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>
<p>Email Address: <input type="text" name="email" size="20" maxlength="80" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
<p>Password: <input type="password" name="pass1" size="10" maxlength="20" /></p>
<p>Confirm Password: <input type="password" name="pass2" size="10" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include ('includes/footer.html');
?>