You are here:

PHP5/PHP Error Messages

Advertisement


Question
I have this code https://gist.github.com/burn123/5009737. 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

Answer
Hi Cody. Please see the code at http://pastebin.com/kSJb9QWK

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 :)

Kevin

PHP5

All Answers


Answers by Expert:


Ask Experts

Volunteer


Kevin Cackler

Expertise

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.

Experience

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.

Education/Credentials
BS - IT/CS

©2016 About.com. All rights reserved.