I am usually going about this problem the following way:
EITHER:
1) Create an array called $error[]
2) Fill it with error messages, depending on you conditions... e.g.
$tindex = sizeof($error)+1;
$error[$index] = "Error: You have not entered your name!";
3) Print out the whole array in red above the form..
OR
if you want the fileds to be highlighted, follow the above procedure, but only store the field IDs (for exampe, because you will need to identify the fields), and then INSERT something like this:
if($error[$id]){
echo "<FONT COLOR=#FF0000>*</FONT>";
}
in front of every field in the form you are validating...
OR
combine the above two, by either creating a two dimensional array --> wastes space(memory), so not a good idea therefore; OR create an Object which will hold a pair with a message and an ID, and then the array will be made up of this objects 🙂)
simple as you see 🙂