Jump to content
Larry Ullman's Book Forums

Script 8.3 - Returning A Blank Page


Recommended Posts

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');
?>

Link to comment
Share on other sites

Hi,

 

Your first error is

if (empty($errors()) {

should be

if (empty($errors)) {

 

You have also forgot to close the quotations on...

$q = "INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() );

 

And finally you have also forgot the semi-colon on this line...

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>'

 

Once I corrected those mistakes the script seems to work on my server. If you have any other problems then feel free to let us know :)

Link to comment
Share on other sites

Hi Craig

Thank you very much for your reply.

 

My problems were actually a little less complicated and I'll just highlight them in case anyone else comes into this problem.

 

 

I'm using the ShiftEdit IDE and when I first created the file I put it in the wrong folder. So using their interface I had cut and paste it into the correct location. They do say the cut and paste options are beta but i thought it had worked. Anyway when I just logged back in to check on the things you highlighted I found that the file had copied but the contents had not so the file my website was directing to was actually empty aside from the opening and closing php tags.

 

After I copied my code into this file and ran it the error reporting began working and the errors craig has highlighted were commented.

 

So basically anyone who might use ShiftEdit IDE be aware that cut and paste or copy and paste does not work as intended.

 

 

 

 

Craig_UK once again thank you very much for taking the time to look at the code :)

Link to comment
Share on other sites

 Share

×
×
  • Create New...