Register page white page?

I’m running on localhost, PHP5 with an Apache server and MySQL. I’m having trouble with my register.php file. Everytime I try to view it on localhost, I only see a blank white page.

<?php
//This is the registration page for the site.

//Include the configuration file for error management and such.
require_once('inc/config.inc');

$page_title = 'Register';
include('inc/header.inc');
include('inc/menu.inc');

if(isset($_POST['submit'])) { //Handle the form.

	require_once('scripts/mysql_connect.php'); //Connect to the database.
		
	//Check for an email address.
	if(eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\\.[a-z]{2,4}$", stripslashes(trim($_POST['email'])))) {
		$e = escape_data($_POST['email']);
	} else {
		$e = FALSE;
		echo '<p><font color="red" size="+1">Please enter a valid email address!</font></p>';
	}
	
	//Check for a username.
	if(eregi{"^[[:alnum:]_]{4,20}$", stripslashes(trim($_POST['username'])))) {
		$u = escape_data($_POST['username']);
	} else {
		$u = FALSE;
		echo '<p><font color="red" size="+1">Please enter a valid username!</font></p>';
	}
	
	//Check for a password and match against the confirmed password.
	if(eregi("^[[:alnum:]]{4,20}$", stripslashes(trim($_POST['password1'])))) {
		$p = escape_data($_POST['password1']);
	} else {
		$p = FALSE;
		echo '<p><font color="red" size="+1">Your password did not match the confirmed password!</font></p>';
	}
} else {
	$p = FALSE;
	echo '<p><font color="red" size="+1">Please enter a valid password!</font></p>';
}

if ($e && $u && $p) {//If everything's OK.

	//Make sure the username is available.
	$query = "SELECT id FROM members WHERE username='$u'";
	$result = @mysql_query($query);
	
	if(mysql_num_rows($result) == 0) { //Available.
	
		//Add the user.
		$query = "INSERT INTO members(username, email, password, created_date) VALUES ('$u', '$e', PASSWORD('$p'), NOW())";
		$result = @mysql_query($query); //Run the query.
		
		if($result) { //If it ran OK.
		
			//Send an email, if desired.
			echo '<h3>Thank you for registering!</h3>';
			include('inc/footer.inc'); //Include the HTML footer.
			exit();
			} else { //If it did not run OK.
				//Send a message to the error log, if desired.
				echo '<p><font color="red" size="+1">You could not be registered due to a system error. We apologize for any inconvenience.</font></p>';
			}
		} else { //The username is not available.
			echo '<p><font color="red" size="+1">That username is already taken.</font></p>';
		}
		
		mysql_close(); //Close the database connection.
		
	} else { //If one of the data tests failed.
		echo '<p><font color="red size="+1">Please try again.</font></p>';
	}
} //End of the main Submit conditional.
?>

<h1>Register</h1>
<form action="<?php echo $SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="40" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>"/></p>
<p><b>Username:</b> <input type="text" name="username" size="30" maxlength="40" value="<?php if(isset($_POST['username'])) echo $_POST['username']; ?>"/></p>
<p><b>Password:</b> <input type="password" name="password1" size="40" maxlength="40" /></p>
<p><b>Confirm Password:</b> <input type="password" name="password2" size="40" maxlength="40" /></p>
</fieldset>

<div align="center"><input type="submit" name="submit" value="Register" /></div>
</form>

<?php include('inc/footer.inc'); ?>
  • It maybe because of some errors in your script and your error display is OFF. So try with following lines on top of the script/file:

error_reporting(E_ALL);
ini_set('display_errors', 1);

BTW, are you sure that you have successfully installed your three of the packages (PHP, MySQL, Apache) and they are running properly? Try a file for phpinfo() and see if that works. Otherwise the page looks just fine and should at least show your HTML page.

You’ve most likely got a parse error in your script. A quick tip don’t use the @ to suppress errors thrown up by MySQL. If your worried about security for a live site then you would have php suppress the display of errors and write the errors to the error log file.

You will probably also want to have E_STRICT errors displayed as well.

AFAIK, @ will suppress the warnings not the errors and warnings don’t stop the script to be executed. Correct me if i am wrong. So at least rest of the script/htmls should have been shown if he has some warnings/notices. So i guess there suspect there is a fatal error or so in the script or included files.

Edit:
As it is said here:
http://php.net/manual/en/language.operators.errorcontrol.php

PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.

That means it suppresses both the errors.:blush:

Thanks for the response guys.

I’m pretty sure I did the installation correct because I did it through MAMP. I also have the errors included in my config.inc script, but it still shows up as a blank white page.


<?php
//This script sets the error reporting and logging for the site.

//error_reporting(0); //Production level 
error_reporting(E_ALL); //Development level
error_reporting(E_STRICT);

//Use my own error-handling function. 
function my_error_handler ($e_number, $e_message) {
	$message = 'An error occured in script ' . __FILE__ .  ' on line ' . __LINE__ . ": $e_message"; //error_log
	($message, 1, 'dyung2@gmail.com'); //Production(send email)
	echo '<font color="red" size="+1">', $message, '</font>'; //Development (print the error in red)
}
set_error_handler('my_error_handler');
?>

To show the errors in the page you need to ON the display_errors flag in php.ini or in your script. Did you try as i said above?


ini_set('display_errors', 1); 

I tried inputting the two codes into my register.php file and it’s still showing nothing. Do I have to echo something out to see it?


error_reporting(E_ALL);
ini_set('display_errors', 1); 

Is the display of errors disabled in php.ini ?

Another method of working out how far down it’s getting is after any if…else blocks to add

echo 'This is Test Point #';

Where # is the next number. It’s a crude method of working out how far a script is getting before failing but it generally works.

OMG! Thank you guys! display_error was indeed off in my php.ini, but fortunately it directed me to my php_error.log and found out that I used ‘{’ instead of ‘(’ in my username validation.