0

my code doesnt seem to work.. the radio buttons appear but nothing beside them .. it seems as if the mysql_fetch_array is not working for some reason as i have played about with the code and repeatedly tested it to find where the code seems to encounter a problem and stop working.. could someone please advise what is wrong? cheers ps. i am new at this, only finished learning the php tutorial on w3schools last few days.

<body>

<?php

include 'dbyear2.php';

          $qnumber = $_REQUEST['uqn']; // obtain question number from URL

         $find = mysql_query("SELECT * FROM Renal WHERE UQN='$qnumber'");

              while($retrieve=mysql_fetch_array($find));
        {

$retrieve['question'] = $question;
$retrieve['MCQ_A'] = $a;
$retrieve['MCQ_B'] = $b;
$retrieve['MCQ_C'] = $c;
$retrieve['MCQ_D'] = $d;
$retrieve['MCQ_E'] = $e;
$retrieve['answer'] = $answer;
$retrieve['MCQ_correct'] = $correct;


   }




  ?>


             <form action='check.php' method='POST'>  

         <table> 

<tr><td></td><td></td></tr>
<tr></tr>
<tr><td><input type='radio' name='group1' value='A' /></td><td> <?php echo $a; ?></td></tr>
<tr><td><input type='radio' name='group1' value='B' /></td><td> <?php echo $b; ?></td></tr>
<tr><td><input type='radio' name='group1' value='C' /></td><td> <?php echo $c; ?></td></tr>
<tr><td><input type='radio' name='group1' value='D' /></td><td> <?php echo $d; ?></td></tr>
<tr><td><input type='radio' name='group1' value='E' /></td><td> <?php echo $e; ?></td></tr> 
<tr>

<?php 

// sending the retrieved information from MYSQL via POST for use in check.php file

$qnumber;
$a;
    $b;
   $c;
      $d;
     $e;
      $answer;
 $correct;


  ?></tr>
       <tr><td><input type="submit" value="Submit"></td></tr>





     </table>

        </form>




      </body>
  </html>
MFA
  • 129
  • 7

2 Answers2

6

This part is backwards:

$retrieve['question'] = $question;
$retrieve['MCQ_A'] = $a;
$retrieve['MCQ_B'] = $b;
$retrieve['MCQ_C'] = $c;
$retrieve['MCQ_D'] = $d;
$retrieve['MCQ_E'] = $e;
$retrieve['answer'] = $answer;
$retrieve['MCQ_correct'] = $correct;

Should be

$question = $retrieve['question' ;
$a = $retrieve['MCQ_A'];
$b = $retrieve['MCQ_B'];
$c = $retrieve['MCQ_C'];
$d = $retrieve['MCQ_D'];
$e = $retrieve['MCQ_E'];
$answer = $retrieve['answer'];
$correct $retrieve['MCQ_correct'];

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

You are also wide open to SQL injections

You should not use w3schools. It's not a reliable source of information and we don't want to encourage its use.

Community
  • 1
  • 1
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • 2
    +1 to the w3schools comment. It's amazing how many people still use their tutorials. They teach everything that's wrong about programming. – Colin M Feb 15 '13 at 00:41
  • absolutely everything – d-_-b Feb 15 '13 at 00:53
  • also +1 for the w3schools comment, mysql_ comment, and injection comment! – Popnoodles Feb 15 '13 at 00:53
  • oh wow, i didnt know the = operator functions in only one direction. i have amended my code as per however it still doesnt work. also, thank you very much for informing me that the mysql API is going to be deprecated - this has saved me alot of future work. However, i am not sure whether i should start using PDO or MySQLi. i read teh article you linked however i dont understand all teh features. MySQLi seems to include everything apart from "API supports client-side Prepared Statements" and im not sure what this means or if i will need this. – MFA Feb 15 '13 at 01:35
0

You are using the wrong direction when assigning. Use this:

$e = $retrieve['MCQ_E'];
Oleg Vaskevich
  • 12,444
  • 6
  • 63
  • 80