Greetings all.

First of all, let me say I am NOT asking for code, just to be pointed in the right direction.

I’m a newbie in php and mysql and have been teaching myself what I could learn from online lessons and tutorials (mostly w3school.com). I have found plenty of information for inputting data into a database or fetching data from a database, but I have find nothing on how to COMPARE input with a database.

What I’m trying to do is develop a quiz for students. I have the quiz designed with radio buttons, I have the mysql database with id, question, options a, b, c, and d, and an answer column that says which of those is correct. But I have no clue what php functions to use to compare the students input with my database so it can mark correct and incorrect answers.

Again, not asking for code, just a nudge in the right direction, particularly which functions would be useful for this sort of thing.

Thanks for your time!

5 Years
Discussion Span
Last Post by Sparhauoc

comparing input from a page to database is done in

Select * From `table_name` WHERE(Compare= What_Is_Your_Input)

the WHERE clause is the input string comparison operator.

this only available when you open the connection function of your MySQL

Edited by masterjiraya: n/a


Also, take a look at arrays for fetching the various answers per question and putting them in the right place.


Thank you both very much for your quick and helpful response!

So, if I understand you correctly, (obviously I would have to write this in code) a possible working example may be something like this?


And then for each question:

mysql_select*From’my_table’ WHERE(Input from quiz form)

IF true (assign value of one)

Else (assign value of zero)

And then at the bottom have a function to add up all the values earned out of a total possible and that be the grade?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.