You are here:

PHP5/PHP Error Messages


I have this code It is basically a question and answer type code, and it is working fine right now. I was wondering how to put the error messages on index.html, so I don't have to do a separate page load for them. So they would only go on to q1.php if they got the right answer

Hi Cody. Please see the code at

This is nice easy, beginner type of code, coded so that it should be fairly easy to follow.

Essentially, what you'll do is check to see if the request was a POST submission. If so, check the posted value to see if it matches. If not, set $error to your error message. If it does match, redirect to q2.php where you can do the same exact thing.

Then, when displaying your form, if $error isn't empty, echo it before the form.

I hope you can follow the code. It is untested, but should work.

Please let me know if you have any other questions :)



All Answers

Answers by Expert:

Ask Experts


Kevin Cackler


Any and everything related to PHP4 and PHP5. I specialize in functional, readable, scalable object oriented code, and can answer your troublesome class and object questions.


5 years developing in PHP using flat files and databases (MySQL, Oracle) Lead PHP developer for a very large Texas based web hosting company The coder behind some of the largest pet communities online.


©2017 All rights reserved.