Selecting random questions from MySQL database; “correct answer” messed up

后端 未结 1 1602
温柔的废话
温柔的废话 2021-02-06 18:20

I am building a simple quiz program, using PHP and MYSQL.

The quiz is designed to display one question at a time; the questions are multiple-choice (each question has 4

1条回答
  •  臣服心动
    2021-02-06 18:22

    When you ask your question to the user, a question is randomly selected from the database.

    Then, the user submits your form, another question is randomly selected, and that's the question you are using to check the answer, instead of the question you asked to the user.

    You need to add an hidden input in your form, that contains the question id

    
    

    And then when you check the answer, be sure to fetch the right question from the database

    The code would look like this

    
    
    
    

    0 讨论(0)
提交回复
热议问题