2010-11-16 119 views
0

我试图创建一个PHP/MySQL的测验时动态生成的单选按钮形式...提交不显示数据

我已创建了答案单选按钮形式显示从数据库中取出的数据作为单选按钮的值。我试图提交表单,但结果页面没有显示任何内容。

我测验的代码去如下:提交页面

<form method="post" action="insertscore.php" name="cssCheckbox" id = "cssCheckbox"> 
<?php $query = "SELECT * FROM questions WHERE (`topics` = '.NET' OR `topics` = 'PHP') ORDER BY Rand() LIMIT 5"; $result = mysql_query($query); 

if ($result && mysql_num_rows($result)) { 
    $numrows = mysql_num_rows($result); 
$count =1; 

while ($row = mysql_fetch_array($result)) 
{ 
?> 

<div class="group"> 
<input type="hidden" name="<?php echo $row['key_id']; ?>"><?php $row['key_id']; ?></input> 
<span class="test_question"><strong><?php echo $count;?>) <?php echo $row['question']; ?> 
</strong><br /> 

<?php if($row['answer1'] != NULL){ ?> 
<input type = "radio" name="answers" value="<?php echo $row['answer1']; ?>" id="chkLimit_1" ></input> 
<label for="chkLimit_1" ><?php echo $row['answer1']; echo "<br />"; } else {} ?></label> 


<?php if($row['answer2'] != NULL){ ?> 
<input type = "radio" name="answers" value="<?php echo $row['answer2']; ?>" id="chkLimit_2" ></input> 
<label for="chkLimit_2" ><?php echo $row['answer2']; echo "<br />"; } else {} ?></label> 

<?php if($row['answer3'] != NULL){ ?> 
<input type = "radio" name="answers" value="<?php echo $row['answer3']; ?>" id="chkLimit_3" ></input> 
<label for="chkLimit_3" ><?php echo $row['answer3']; echo "<br />"; } else {} ?></label> 

<?php if($row['answer4'] != NULL){ ?> 
<input type = "radio" name="answers" value="<?php echo $row['answer4']; ?>" id="chkLimit_4" ></input> 
<label for="chkLimit_4" ><?php echo $row['answer4']; echo "<br />"; } else {} ?></label> 

<?php if($row['answer5'] != NULL){ ?> 
<input type = "radio" name="answers" value="<?php echo $row['answer5']; ?>" id="chkLimit_5" ></input> 
<label for="chkLimit_5" ><?php echo $row['answer5']; echo "<br />"; } else {} ? ></label> 

<?php if($row['answer6'] != NULL){ ?> 
<input type = "radio" name="answers" value="<?php echo $row['answer6']; ?>" id="chkLimit_6" ></input> 
<label for="chkLimit_6" ><?php echo $row['answer6']; echo "<br />"; } else {} ?></label> 

<?php if($row['answer7'] != NULL){ ?> 
<input type = "radio" name="answers" value="<?php echo $row['answer7']; ?>" id="chkLimit_7" ></input> 
<label for="chkLimit_7" ><?php echo $row['answer7']; echo "<br />"; } else {} ?></label> 

<?php if($row['answer8'] != NULL){ ?> 
<input type = "radio" name="answers" value="<?php echo $row['answer8']; ?>" id="chkLimit_8" ></input> 
<label for="chkLimit_8" ><?php echo $row['answer8']; echo "<br />"; } else {} ?></label> 

<input type="hidden" name="<?php echo $row['right_answer']; ?>"><?php $row['right_answer']; ?></input> 
</div> 
<input name="Submit" type="submit" value="Submit Your Answers" class="submit"> 

</form> 

代码如下所示:

<?php 

if(isset($_POST['Submit'])){ 

$key_id=$_POST['key_id']; echo $key_id; 

$question=$_POST['question']; echo $question; 

$answers=$_POST['answers']; echo $answers; 

$correctanswer=$_POST['correctanswer']; echo $correctanswer; 

} 


foreach($_POST as $key => $val) 
{ 
echo "$key --> $val<br />"; 
} 


//var_dump($_POST); 
?> 

请让我知道如果有什么不明确或者如果我缺少什么? 。

感谢,

+0

你确定'insertscore.php',我认为是上面显示的最后一个代码片段是“没有显示任何东西的结果页”?你能告诉我们结果页面的HTML源吗? – stillstanding 2010-11-16 19:34:19

+0

@stillstanding:我很惊讶你要求看到更多的代码,而不是他已经写在那里的所有东西。 :) – 2010-11-16 19:53:35

+0

@stillstanding:在结果页上我试图显示提交的表单的返回值,这是由foreach完成的... – Shank 2010-11-17 02:33:16

回答

1

我想:

  1. 删除评论//var_dump($_POST);并在代码的顶部上提交页移动这条线。

  2. 如果您仍然看不到任何东西,我认为提交页面上的代码不在insertscore.php文件中,或者此文件不在您的表单页面的同一文件夹中。

+0

Marco:Ty的评论... 1)我会让你知道,我尝试了上述事情后。 .. 2)第二个块中的代码位于与表单页面位于同一文件夹中的insertscore.php文件中。 – Shank 2010-11-17 02:39:54

+0

我尝试将var_dump移动到页面顶部,并将结果设置为零除了最后一个答案之外的答案(显示正确.. – Shank 2010-11-17 14:46:25