将$ _get结果与db存储值进行比较

i have a multiple choice quiz which sends a possible answer via URL like this

<form method="post" action="test2score.php?q=<?php echo $quiz_id; ?>">

on the test2score.php page it reads and tries to compare the value like this

$ans = mysql_result(mysql_query('select c_answer from quiz where quiz_id = "'.$_GET['q'].'"'),0);
    if ($_POST['answer'] == $ans){
        echo "You got it right!";
    }else if ($_POST['answer'] <> $ans){
        echo "You got it wrong!";
    }

where c_answer is the correct answer stored in db, but even when i select the right answer and post it it still echoes "you got it wrong"

any help would be appreciated.

Your form method="post" is post and your receiving values in $_GET['q'] Kindly correct either of the one Or use

$_REQUEST['q']`

Use a hidden field q and post that value to your action page and receive that value using

$_POST['q'] and use that in your query.

Thanks.

Why are you using a $_GET request in the action of a form that is $_POST? Since you aren't worried about your users seeing the value of q then why not just put a hidden input in the form with the results of q:

<input type="hidden" value=<?php echo $quiz_id ?> name="q" />

Then in your query, check for $_POST['q']

Seems the saner, more logical way to achieve this

instead of passing quiz id from form action pass it from hidden form field

like below set form action to

action="test2score.php"

and take hidden form field as

<input type="hidden" name="q" value=<?php echo $quiz_id; ?> />

and get that value like below

$_POST['q'];