Hey guys,

I have reached my wits end with this..! This code works on two of the servers that I have tested, but doesn't want to work on the third server that I need it on! It displays fine, but when the form data is posted back itself to be validated, I get a blank page - No error messages or clues as to what may be causing the problem.

<?php //session_start();



//THIS FUNCTION VALIDATES ALL USER INPUT

function VerifyForm(&$values, &$error) {



   if (strlen($values['title']) == 0) {

		$error['title'] = 'Please specify your title';

   }

   if (strlen($values['firstname']) == 0) {

		$error['firstname'] = 'Please Enter a name';

   }

   if (strlen($values['surname']) == 0) {

		$error['surname'] = 'Plese Enter a surname';

   }

   if (strlen($values['address1']) == 0) {

		$error['address1'] = 'Please enter the first line of your address';	

   }

   if (strlen($values['address2']) == 0) {

		$error['address2'] = 'Please enter you street name';	

   }	

   if (strlen($values['city']) == 0) {

		$error['city'] = 'Please enter your town/city';		

   }

   if (strlen($values['postcode']) == 0) {

		$error['postcode'] = 'Please enter your postcode';

   }

   elseif (strlen($values['postcode']) < 6) {

		$error['postcode'] = 'Specified Postcode is too short';	

   }

   elseif (!preg_match("/^([Gg][Ii][Rr]0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))){0,1}[0-9][A-Za-z]{2})$/",$values['postcode'])) {   	

		$error['postcode'] = 'Invalid postcode entered';   	

   }

   if (strlen($values['county']) == 0) {

		$error['county'] = 'Please enter your county';

   }	

   if (strlen($values['region']) == 0) {

		$error['region'] = 'Please select a region';   	

   }	

   if (strlen($values['telephone']) == 0) {

		$error['telephone'] = 'Please enter a contact telephone number';

   }

   elseif (strlen($values['telephone']) < 11) {

		$error['telephone'] = 'telephone number too short';

		$values['telephone'] = ereg_replace('[^0-9]', '', $_POST['telephone']);

   }

   if (!filter_var($values['telephone'], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => "/^0[1-9][0-9]{8,9}$/")))) {  

		$error['telephone'] = 'Invalid number';

   }

   if (strlen($values['email']) == 0) {

		$error['email'] = 'Please enter a valid e-mail address';

   }	

   elseif(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $values['email'])) {

    	$error['email'] = 'please enter a real email';

   }

   if (strlen($values['date']) == 0) {

		$error['date'] = 'Please select a date<br>';	   

   }	

   if (strlen($values['month']) == 0) {

		$error['month'] = 'Please select a month<br>';	

   }	

   if (strlen($values['year']) == 0) {

		$error['year'] = 'Please enter a year<br>';

   }	

   elseif (intval($values['year']) < 1890) {

		$error['year'] = 'You must be alive to use this service!';

   }

   elseif (intval($values['year']) > 1992) {

		$error['year'] = 'You must 18 to use this service';

   }   

   if (strlen($values['username']) == 0) {

		$error['username'] = 'Please specify a username between 5-25 characters';	

   }

   elseif (strlen($values['username']) < 5) {

		$error['username'] = 'Specified Username is too short';

   }

   elseif (strlen($values['username']) > 25) {

		$error['username'] = 'Username too long';    

   }   

   if (strlen($values['password']) == 0) {

		$error['password'] = 'Please specify a password';		

   }

   elseif (strlen($values['password']) < 5) {

		$error['password'] = 'Specified Password is too short';	    

   }    	 

   if (strlen($values['password2']) == 0) {

		$error['password2'] = 'Please re-enter your password';								

   }

   if(strcmp($values['password'], $values['password2'])!= 0) {

		$error['password2'] = 'Passwords do not match';   

   }

    $_SESSION['formdata'] = $values;

	return (count($error) == 0);

}



function DisplayForm($values, $error)

{

?>



<html>

<head>
		<link type="text/css" rel="stylesheet" href="/ece60363/style.css" />
</head>

<body background="/ece60363/images/back.gif" alink="#00ff00" link="#00c000" bgcolor="#000000" link="#00c000" vlink="#00c000" text="#00ff00" >

<center>

<div id="container">
<div id=content>

Don't have an account? <a href ="/ece60363/register.php">Register</a> to start creating your own personalised auction!

<h3>Computabid is FREE and anyone can join!</h3></a><hr>

	<table cellpadding="2px">

		<tr>

			<td colspan="3" class="error">

				<?php

					if (count($error) > 0) {

						echo "Ooops! There were some errors in your form..."; 

					}

				?>

			</td>

		</tr>

	<form name="registerform" action="<?php echo htmlentities($_SERVER['PHP_SELF']) ?>" method="POST">
		
		<tr>

			<td>Gender:</td>

			<td><select name="title" <?php echo htmlentities($values['title']) ?> value="<?php echo $_SESSION['formdata']['title']; ?>">

			<option value="">-Title-</option><option value="mr">Mr</option>

			<option value="mrs">Mrs</option><option value="miss">Miss</option>

			<option value="ms">Ms</option><option value="dr">Dr</option>

			<option value="prof">Prof</option>

			</td>

			<td><?php echo $error['title'] ?></td>

		</tr>
		<tr>

			<td>First Name:</td>

			<td><input type="text" name="firstname" maxlength="40" <?php echo htmlentities($values['firstname']) ?> value="<?php echo $_SESSION['formdata']['firstname']; ?>"></td>

			<td class="error"><?php echo $error['firstname'] ?></td>

		</tr>
		<tr>

			<td>Surname:</td>

			<td><input type="text" name="surname" maxlength="40" <?php echo htmlentities($values['surname']) ?> value="<?php echo $_SESSION['formdata']['surname']; ?>"></td>

			<td class="error"><?php echo $error['surname'] ?></td>

		</tr>
		<tr>

			<td>House no/name:</td>

			<td><input type="text" name="address1" maxlength="80" <?php echo htmlentities($values['address1']) ?> value="<?php echo $_SESSION['formdata']['address1']; ?>"></td>

			<td class="error"><?php echo $error['address1'] ?></td>

		</tr>
		<tr>

			<td>Street name:</td>

			<td><input type="text" name="address2" maxlength="100" <?php echo htmlentities($values['address2']) ?> value="<?php echo $_SESSION['formdata']['address2']; ?>"></td>

			<td class="error"><?php echo $error['address2'] ?></td>

		</tr>
		<tr>

			<td>Town/City:</td>

			<td><input type="text" name="city" maxlength="100" <?php echo htmlentities($values['city']) ?> value="<?php echo $_SESSION['formdata']['city']; ?>"></td>

			<td class="error"><?php echo $error['city'] ?></td>

		</tr>
		<tr>

			<td>Postcode:</td>

			<td><input type="text" name="postcode" maxlength="8" size="8" <?php echo htmlentities($values['postcode']) ?> value="<?php echo $_SESSION['formdata']['postcode']; ?>"></td>

			<td class="error"><?php echo $error['postcode'] ?></td>

		</tr>
		<tr>

			<td>County:</td>

			<td><input type="text" name="county" maxlength="50" <?php echo htmlentities($values['county']) ?> value="<?php echo $_SESSION['formdata']['county']; ?>"></td>

			<td class="error"><?php echo $error['county'] ?></td>

		</tr>
		<tr>

			<td>Region:</td>

			<td><select name="region" <?php echo htmlentities($values['region']) ?> value="<?php echo $_SESSION['formdata']['region']; ?>">

			<option value="" selected="-Region-">--Region--</option>

			<option value="England">England</option>

			<option value="Wales">Wales</option>

			<option value="Scotland">Scotland</option>

			<option value="Ireland">Ireland</option></select></td>

			<td class="error"><?php echo $error['region'] ?></td>

		</tr>
		<tr>

			<td>Telephone:</td>

			<td><input type="text" name="telephone" maxlength="11" size="11" <?php echo htmlentities($values['telephone']) ?> value="<?php echo $_SESSION['formdata']['telephone']; ?>"></td>

			<td class="error"><?php echo $error['telephone'] ?></td>

		</tr>
		<tr>

			<td>Email:</td>

			<td><input type="text" name="email" maxlength="100" <?php echo htmlentities($values['email']) ?> value="<?php echo $_SESSION['formdata']['email']; ?>"></td>

			<td class="error"><?php echo $error['email'] ?></td>

		</tr>
		<tr>

			<td>Date of Birth:</td>

			<td><select name="date" <?php echo htmlentities($values['date']) ?> value="<?php echo $_SESSION['formdata']['date']; ?>">

			<option value="">-Day-</option>

			<option value="1">01</option><option value="2">02</option><option value="3">03</option>

			<option value="4">04</option><option value="5">05</option><option value="6">06</option>

			<option value="7">07</option><option value="8">08</option><option value="9">09</option>

			<option value="10">10</option><option value="11">11</option><option value="12">12</option>

			<option value="13">13</option><option value="14">14</option><option value="15">15</option>

			<option value="16">16</option><option value="17">17</option><option value="18">18</option>

			<option value="19">19</option><option value="20">20</option><option value="21">21</option>

			<option value="22">22</option><option value="23">23</option><option value="24">24</option>

			<option value="25">25</option><option value="26">26</option><option value="27">27</option>

			<option value="28">28</option><option value="29">29</option><option value="30">30</option>

			<option value="31">31</option></select>



		<select name="month" <?php echo htmlentities($values['month']) ?> value="<?php echo $_SESSION['formdata']['month']; ?>">

			<option value="">-Month-</option><option value="1">January</option>

			<option value="2">February</option><option value="3">March</option>

			<option value="4">April</option><option value="5">May</option>

			<option value="6">June</option><option value="7">July</option>

			<option value="8">August</option><option value="9">September</option>

			<option value="10">October</option><option value="11">November</option>

			<option value="12">December</option></select>

			<input type="text" name="year" maxlength="4" size="4" <?php echo htmlentities($values['year']) ?> value="<?php echo $_SESSION['formdata']['year']; ?>"></td>

			<td class="error"><?php echo $error['date'] ?><?php echo $error['month'] ?><?php echo $error['year'] ?></td>

		</tr>

		<tr><td height="10"></td></tr>

		<tr>

			<td>Username:</td>

			<td><input type="text" name="username" maxlength="30" <?php echo htmlentities($values['username']) ?> value="<?php echo $_SESSION['formdata']['username']; ?>"></td>

			<td class="error"><?php echo $error['username'] ?></td>

		</tr>
		<tr>

			<td>Password:</td>

			<td><input type="password" name="password" maxlength="32" <?php echo htmlentities($values['password']) ?>></td>

			<td class="error"><?php echo $error['password'] ?></td>

		</tr>
		<tr>

			<td>Re-enter Password</td>

			<td><input type="password" name="password2" maxlength="32" <?php echo htmlentities($values['password2']) ?>></td>

			<td class="error"><?php echo $error['password2'] ?></td>

		</tr>
		<tr><td></td></tr>
		<tr>

			<td colspan="3" align="center" valign="baseline"><input type="submit" value="Register"</td>

		</tr>
	</form>
</table>

</div>

<div id="footer">
		Page revised 4th March 2010 • &copy;335122 • 2009
</div>
</div>
</body>
</html>

<?php

}

// PROCESS THE FORM DATA

function ProcessForm($values)

{   

	 //echo ('window.location.replace(" http://localhost/register_server.php ")');

	header("Location: https://students.ee.port.ac.uk/ece60363/register_server.php");

}

if ($_SERVER['REQUEST_METHOD'] == 'POST')

{

    $formValues = $_POST;

    $formErrors = array();

    if (!VerifyForm($formValues, $formErrors))

        DisplayForm($formValues, $formErrors);

    else

        ProcessForm($formValues);

}

else

    DisplayForm(null, null);

?>

Any ideas why this wouldn't work?
Thanks

I have found the problem...

It was with with this validation regular expression for telephone number:

if (!filter_var($values['telephone'], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => "/^0[1-9][0-9]{8,9}$/")))) {  

		$error['telephone'] = 'Invalid number';

   }

Thanks anyway
nonshatter

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.