form validation and error process

I’ve taken this as an extract of a much larger file.

If $score1 is empty the no score message appears, the exit() occurs. and the footer div will not appear.
If $score1 is filled, the success message and the footer div both appear fine.

If I remove the exit, then both the success and the no score message appears, and the footer div displays fine.

I would like the no score message to appear when $score1 is empty, aswell as the footer div to appear.

How should I restructure my code so that is so?

Any basic examples would be great!

<input type="text"   name="score1"/>
<input type="text"   name="score2"/>

	   $score1 = $_POST['score']; 
	   if (empty($score1)) {echo "You haven't entered a score for score2"; exit();}
	   else if (empty($score2)) {echo "You haven't entered a score for score1"; exit();}
#connection here
echo "success message";  
<div id="footer">Footer</div>

All your processing code need to go on top of the page. Set your error messages as variables, then display them in the correct place, use if(isset()) statements. The error messages are mixed up too. If score1 is empty, it needs to say that, not score2. Same goes for score2.

You should never have to use exit, because as you can see, it kills the entire page, not just the script.

Sponsor our Newsletter | Privacy Policy | Terms of Service