提交时动态生成的单选按钮表单不显示数据

时间:2010-11-16 19:01:20

标签: php mysql html

我正在尝试用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);
?>

如果有什么不清楚或者我遗失了什么,请告诉我。

谢谢,

1 个答案:

答案 0 :(得分:1)

我会:

  1. 删除对//var_dump($_POST);的评论,并将此行移至提交的网页代码顶部

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