Hi all
I'm a relative newbie to PHP but have been programming for 15+ years.
I have created a PHP page for users to register their details which works fine when a user enters their details correctly but if they enter an email address that is already in use and then correct it, none of the form fields are passed through to the form submission page. (I have included the relevant value="'<?php $_POST['forename']?>" where necessary and these values are displayed when the form redisplays.)
Apologies if this is a very basic question but I've been stuck on this for a number of days now and although I can't really afford any more time trying to resolve this I know I have to get it right.
Thanks in advance.
My codes is as follows:
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Fri, 31 Dec 1999 00:00:00 GMT");
include('/inc/db.php');
$email_msg = '';
if (!empty($_POST))
{
$email = mysql_real_escape_string($_POST['email']);
$query = mysql_query("SELECT * FROM table WHERE email = '$email'");
$check = mysql_num_rows($query);
if ($check > 0)
{
$email_msg = "<label for='email' class='error'>This email address is already in use</label>";
$forename = mysql_real_escape_string($_POST['forename']);
$surname = mysql_real_escape_string($_POST['surname']);
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$password2 = mysql_real_escape_string($_POST['password2']);
$email = mysql_real_escape_string($_POST['email']);
$dob = mysql_real_escape_string($_POST['dob']);
}
else
{
// register_db.php doesn't receive a value for $_POST['forename'] or any of the other fields
header('location: /inc/register_db.php');
exit;
}
}
echo "
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<script type='text/javascript' src='/js/jquery-1.3.2.min.js'></script>
<script type='text/javascript' src='/js/jquery.validate.pack.js'></script>
<link rel='stylesheet' type='text/css' media='projection, screen' href='/css/ui-lightness/jquery-ui-1.7.2.custom.css' />
</head>
<body id='register-body'>
<div id='page-header'>
<div id='logo'>
<h1><a accesskey='1' href='index.php'>HOMEPAGE</a></h1>
</div>
</div>
<div id='register-page'>
<form id='register-details' method='post' action='/inc/register_db.php'>
<div id='column1'>
<h3><label for='forename'>FORENAME</label></h3>
<input type='text' id='forename' name='forename' class='required' tabindex='1000' value='$forename' />
<br />
<br />
<h3><label for='surname'>SURNAME</label></h3>
<input type='text' id='surname' name='surname' class='required' tabindex='1010' value='$surname' />
<br />
<br />
<h3><label for='username'>USERNAME</label></h3>
<input type='text' id='username' name='username' class='required' tabindex='1020' value='$username' />
<br />
<br />
<h3><label for='password'>PASSWORD</label></h3>
<input type='password' id='password' name='password' class='required' tabindex='1030' value='$password' />
<br />
<br />
<h3><label for='password2'>RETYPE PASSWORD</label></h3>
<input type='password' id='password2' name='password2' class='required' tabindex='1040' value='$password2' />
<br />
</div>
<div id='column2'>
<h3><label for='email'>EMAIL ADDRESS</label></h3>
<input type='text' id='email' name='email' class='required email' tabindex='1050' value='$email' />
$email_msg
<br />
</div>
<div id='column3'>
<h3><label for='country'>LOCATION</label></h3>
<select id='country' name='country' class='required' tabindex='1060'>
<option value=''>Please select</option>
<option value='1'>United Kingdom</option>
<option value='2'>United States</option>
<option value='3'>Canada</option>
</select><br />
</div>
<div id='column4'>
<h3><label for='dob'>DATE OF BIRTH</label></h3>
<input type='text' id='dob' name='dob' class='required date' tabindex='1070' value='$dob' />
<br />
<input type='submit' id='register-button' name='register-button' value='register!' />
</div>
</form>
</div>
</body>
</html>";
?>