Jump to content

Recommended Posts

I'm trying to make a php registration form. In the form I have one section where it randomly selects a question from the mysql table

$queryquestion = 'SELECT * FROM question ORDER BY RAND() LIMIT 1';
if ($resultquestion = mysql_query ($queryquestion)) {
while ($qrow = mysql_fetch_array ($resultquestion)) {
$question = $qrow['question'];
$answer = $qrow['answer'];
}
}

 

Then in the isset submit for the form I have the following to check if the answer is correct

if ($_POST['answer'] == "$answer") {
//good we move on
}
else {
echo "wrong answer";
}

 

The issue is when submit is click I always get the else statement for wrong answer. I'm thinking everytime I click submit a new random answer from the table gets compared to the post answer.

 

How can I solve this issue?

http://www.phpfreaks.com/forums/index.php/topic,249639.msg1169928.html#msg1169928

 

You would need to use a session to pass the information between different pages or different requests of the same page.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.