dmilani
08-13-2008, 10:29 PM
I have some code I am trying to customize for my site.
Submitting the form leads me to a blank page. Inspecting the source code for this page shows me that it is only the header.html section included in the script. Even with all errors being reported I can't get any hints about what's happening.
I been staring at this all day and hoping a new pair of eyes might help.
<?php
error_reporting(E_ALL);
ini_set('display_errors','On') ;
$page_title = 'Register';
include ('header.html');
echo '<div id=\"form\">' ;
// Check if the form has been submitted:
if (isset($_POST['submitted'])) {
require_once ('mysqli_connect.php'); // Connect to the db. $dbc is set here
// $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );
$errors = array(); // Initialize an error array.
// Check for a first name:
if (empty($_POST['fname'])) {
$errors[] = 'You forgot to enter your first name.';
} else {
$fn = mysqli_real_escape_string($dbc, trim($_POST['fname']));
}
// Check for a last name:
if (empty($_POST['lname'])) {
$errors[] = 'You forgot to enter your last name.';
} else {
$ln = mysqli_real_escape_string($dbc, trim($_POST['lname']));
}
// 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']));
}
// Check for a password and match against the confirmed password:
if (!empty($_POST['pass'])) {
if ($_POST['pass'] != $_POST['passconf']) {
$errors[] = 'Your password did not match the confirmed password.' ;
} else {
$p = mysqli_real_escape_string($dbc, trim($_POST['pass']));
}
} else {
$errors[] = 'You forgot to enter your password.';
}
if (empty($errors)) { // If everything's OK.
// Register the user in the database...
// Make the query:
$q = "INSERT INTO contacts VALUES ('$e', password('$p'), '$fn', '$ln', '$d', '$ev', '$ce', '$contactid', NOW() )";
$result = @mysqli_query ($dbc, $q); // Run the query.
if ($result) { // If it ran OK.
// Print a message:
echo '<h1>Thank you!</h1>
<p>You are now registered. In Chapter 11 you will actually be able to log in!</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 ($result) IF.
mysqli_close($dbc); // Close the database connection.
// Include the footer and quit the script:
include ('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.
?>
<p class="header">Travel Team and High School Registration</p>
<p>We have upgraded our registration system. Please create an account.<br>
* denotes a required field</p>
<form action="register.php" method="post">
<p>First Name: <input type="text" name="fname" size="15" maxlength="20" value="<?php if (isset($_POST['fname'])) echo $_POST['fname']; ?>" /></p>
<p>Last Name: <input type="text" name="lname" size="15" maxlength="40" value="<?php if (isset($_POST['lname'])) echo $_POST['lname']; ?>" /></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="pass" size="10" maxlength="20" /></p>
<p>Confirm Password: <input type="password" name="passconf" size="10" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
</div>
<?php
include ('footer.html');
?>
Submitting the form leads me to a blank page. Inspecting the source code for this page shows me that it is only the header.html section included in the script. Even with all errors being reported I can't get any hints about what's happening.
I been staring at this all day and hoping a new pair of eyes might help.
<?php
error_reporting(E_ALL);
ini_set('display_errors','On') ;
$page_title = 'Register';
include ('header.html');
echo '<div id=\"form\">' ;
// Check if the form has been submitted:
if (isset($_POST['submitted'])) {
require_once ('mysqli_connect.php'); // Connect to the db. $dbc is set here
// $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );
$errors = array(); // Initialize an error array.
// Check for a first name:
if (empty($_POST['fname'])) {
$errors[] = 'You forgot to enter your first name.';
} else {
$fn = mysqli_real_escape_string($dbc, trim($_POST['fname']));
}
// Check for a last name:
if (empty($_POST['lname'])) {
$errors[] = 'You forgot to enter your last name.';
} else {
$ln = mysqli_real_escape_string($dbc, trim($_POST['lname']));
}
// 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']));
}
// Check for a password and match against the confirmed password:
if (!empty($_POST['pass'])) {
if ($_POST['pass'] != $_POST['passconf']) {
$errors[] = 'Your password did not match the confirmed password.' ;
} else {
$p = mysqli_real_escape_string($dbc, trim($_POST['pass']));
}
} else {
$errors[] = 'You forgot to enter your password.';
}
if (empty($errors)) { // If everything's OK.
// Register the user in the database...
// Make the query:
$q = "INSERT INTO contacts VALUES ('$e', password('$p'), '$fn', '$ln', '$d', '$ev', '$ce', '$contactid', NOW() )";
$result = @mysqli_query ($dbc, $q); // Run the query.
if ($result) { // If it ran OK.
// Print a message:
echo '<h1>Thank you!</h1>
<p>You are now registered. In Chapter 11 you will actually be able to log in!</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 ($result) IF.
mysqli_close($dbc); // Close the database connection.
// Include the footer and quit the script:
include ('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.
?>
<p class="header">Travel Team and High School Registration</p>
<p>We have upgraded our registration system. Please create an account.<br>
* denotes a required field</p>
<form action="register.php" method="post">
<p>First Name: <input type="text" name="fname" size="15" maxlength="20" value="<?php if (isset($_POST['fname'])) echo $_POST['fname']; ?>" /></p>
<p>Last Name: <input type="text" name="lname" size="15" maxlength="40" value="<?php if (isset($_POST['lname'])) echo $_POST['lname']; ?>" /></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="pass" size="10" maxlength="20" /></p>
<p>Confirm Password: <input type="password" name="passconf" size="10" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
</div>
<?php
include ('footer.html');
?>