Thanks for the reply but I still couldn't get it working - could it be a caused by different versions of PHP? I'm using 5.1.2
Anyway, after playing around a bit I've finally got it working (I think!). For reference, here's the amended code:
<html>
<body>
<h3>PHP User Form</h3>
<?php
// only validate form when form is submitted
$first_name_input = '';
$last_name_input = '';
$username_input = '';
$password_input = '';
$email_input = '';
if(isset($_POST['submit_button'])){
$first_name_input = $_POST['first_name_input'];
$last_name_input = $_POST['last_name_input'];
$username_input = $_POST['username_input'];
$password_input = $_POST['password_input'];
$email_input = $_POST['email_input'];
$error_msg='';
if(trim($username_input)=='' || strlen(trim($username_input)) < 6 || strlen(trim($username_input)) > 15) {
$error_msg.="Please enter a username between 6 to 15 characters long<br>";
}
if(trim($password_input)=='' || strlen(trim($password_input)) < 4) {
$error_msg.="Please enter a password at least 4 characters long<br>";
}
if(trim($email_input)=='') {
$error_msg.="Please enter an email<br>";
} else {
// check if email is a valid address in this format [email]username@domain.com[/email]
if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $email_input)) $error_msg.="Please enter a valid email address<br>";
}
// display error message if any, if not, proceed to other processing
if($error_msg==''){//uncomment the line below to go to another page without using a header
//and change the done.php to whatever URL you need
//echo "<script type=\"text/javascript\">window.location=\"InsertContactDetails3.php\"</script>";
} else {
echo "<font color=red>$error_msg</font>";
}
}
?>
<form method="POST" action="form.php">
<table border="1" cellpadding="7" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
<tr>
<td width="16%" align="right">First Name</td>
<td width="84%">
<input type="text" name="first_name_input" size="20" value="<?php echo $first_name_input; ?>"></td>
</tr>
<tr>
<td width="16%" align="right">Last Name</td>
<td width="84%">
<input type="text" name="last_name_input" size="20" value="<?php echo $last_name_input; ?>"></td>
</tr>
<tr>
<td width="16%" align="right">Username</td>
<td width="84%">
<input type="text" name="username_input" size="20" value="<?php echo $username_input; ?>"> (between
6 to 15 characters)</td>
</tr>
<tr>
<td width="16%" align="right">Password</td>
<td width="84%">
<input type="password" name="password_input" size="20" value="<?php echo $password_input; ?>">
(must be at least 4 characters)</td>
</tr>
<tr>
<td width="16%" align="right">Email</td>
<td width="84%">
<input type="text" name="email_input" size="20" value="<?php echo $email_input; ?>"></td>
</tr>
<tr>
<td width="16%" align="right"> </td>
<td width="84%">
<input type="submit" value=" Register " name="submit_button"></td>
</tr>
</table>
</form>
</body>
</html>
Thanks for all your help.