I'm sorry, I forgot something. I realise that if you have say 4 or 5 or more variables that the if statement may get cluttered,
PHP Code:
# Bad:
if(empty($var1)||empty($var2)||empty($var3)||empty($var4)||empty($var5) #etc.)
you may choose to run a foreach loop and check each. But for this to work you will have to store the variables in an array (which you should do anyway):
PHP Code:
# note format for array 'varName'=>'value' and is referenced on the page as $arrayName['varName'];
$vars = array(
'var1'=>$_POST['varName1'],
'var2'=>$_POST['varName2'],
'var3'=>$_POST['varName3'],
'var4'=>$_POST['varName4']); # Add/subtract as necessary
$errors = array(); # Array of errors for easy display
# Loop each value of the array
foreach($vars as $values) {
# If it is empty tell them (empty checks for strLen($var) == 0 as well)
if(empty($values) || !isset($values)) {
$errors[]= 'Empty value';
}
}
# ...
# What to display if errors
if($errors) {
echo "Errors: <ul><li>";
echo implode("</li><li>",$errors);
echo "</li></ul> <a href='linkBackToForm'>Try again</a>";
exit;
}
#...
That way it runs the loop through every value and checks with one simple if() statement. Much more efficient too.