Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you don't want to include a hidden value for the right answer as anyone can check the source. you want to add a parameter 'name' to your radio buttons and include a hidden value for the question number to check against it's correct value in check_value.php. In your example you do a SELECT * // WHERE sual_id=1; I assume that the id relates to the question number. In addition you should value your radio buttons as 0, 1, 2 instead of storing entire strings in there as comparing strings takes longer.</p> <pre><code>&lt;input type="radio" name="answer" value="'.$answer0.'"&gt;'.$answer0."&lt;br&gt;"; &lt;input type="radio" name="answer" value="'.$answer1.'"&gt;'.$answer1."&lt;br&gt;"; &lt;input type="radio" name="answer" value="'.$answer2.'"&gt;'.$answer2."&lt;br&gt;"; &lt;input type="hidden" name="question_number" value="'.$question_number.'" /&gt; </code></pre> <p>when posted to question_check.php, you will have access to $_POST['answer'] and $_POST['question_number']. </p> <pre><code>if(isset($_POST['answer']) &amp;&amp; isset($_POST['question_number'])) { $answer=$_POST['answer']; $question_number=$_POST['question_number']; $result=mysql_query("select 'rightanswer' from sual where sual_id='$question_number'"); if(mysql_num_rows($result)) { $row=mysql_fetch_row($result); if($row[0]==$answer){ //correct answer //$answer_result++; } else { //$answer_result--; } } } else { //no answer and a question number was posted } </code></pre> <p>EDIT: Also I agree that you should look into PDO (php data object) as it's parametrised queries (SELECT something FROM somewhere WHERE something=?) can be bound to variables and the mechanism behind it will render SQL injection attacks useless. Never trust the users!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload