Now that I have a few minutes, here is a basic illustration of what I was talking about. This is a basic jumping off point for validation and input error handling methods, and can be built upon to include placing the messages next to the field to which it applies, etc. Look through it, and if you have questions, please ask.
<?php
if( $_POST['submitted'] == 'true' ) { // if the hidden field's value is present, the form has been submitted. This caters to some browsers weaknesses in handling submit buttons.
$errors = array(); // initialize an array to hold error messages
if( empty($_POST['user_name']) ) {
$errors[] = 'Username may not be blank';
}
if( empty($_POST['password']) || empty($_POST['password_conf']) ) {
$errors[] = 'Password and password confirmation fields are both required.';
} else {
if( $_POST['password'] != $_POST['password_conf'] ) {
$errors[] = 'Password and password confirmation fields must match.';
}
}
if( empty($errors) ) {
// Here is the code that is processed if the form has been submitted and there are no validation errors. Database insert, update, whatever.
}
}
?>
<html>
<head>
<title>Test page for field validation</title>
</head>
<body>
<?php
if( !empty($errors) ) { // starts the display process if the $errors array is not empty.
$num = count($errors);
$i = 1;
foreach( $errors as $value ) { // Loops through the $errors array, and displays each error for the user.
echo "<font color=\"red\">$value</font>";
if( $i < $num ) { // This conditional inserts a <br /> unless it's the last error message.
echo '<br />';
}
$i++;
}
}
?>
<form action="" method="post">
Username: <input type="text" name="user_name" /><br />
Password: <input type="password" name="password" /><br />
Re-type Password: <input type="password" name="password_conf" /><br />
<input type="hidden" name="submitted" value="true" />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>