2013-02-15 112 views
0

我的代碼似乎沒有工作..單選按鈕出現,但沒有在他們旁邊..它似乎像mysql_fetch_array不工作的原因,因爲我已經玩了代碼,並反覆測試它找到代碼似乎遇到問題的地方,並停止工作..可有人請告知什麼是錯的?歡呼ps。我是新手,最近幾天才完成了關於w3schools的php教程。PHP回聲不起作用

<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> 

回答

0

分配時使用了錯誤的方向。使用此:

$e = $retrieve['MCQ_E']; 
+0

我改變了這一點,但它仍然無法正常工作。任何其他建議? – MFA 2013-02-15 11:52:58

6

這部分是向後:

$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; 

應該

$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。他們不再維護and are officially deprecated。查看red box?請改爲了解prepared statements,並使用PDOMySQLi - this article將幫助您決定哪個。如果您選擇PDO,here is a good tutorial

你也來SQL injections

敞開你不應該使用w3schools。這不是一個可靠的信息來源,我們不想鼓勵它的使用。

+2

+1給w3schools評論。很多人仍然在使用他們的教程令人驚訝。他們教授關於編程的所有錯誤。 – 2013-02-15 00:41:06

+0

絕對應有盡有 – 2013-02-15 00:53:24

+0

也爲w3schools評論,mysql_評論和注入評論+1! – Popnoodles 2013-02-15 00:53:32