为什么我的数据没有显示?

时间:2014-04-12 18:43:19

标签: php

我有一个带单选按钮的页面,当提交时,它应该显示到quiz_layout.php页面。布局页面应仅根据提交的单选按钮显示测验。谁能帮我?我不确定为什么我的数据没有显示。

第1页:quiz_main.php

//form for selecting quiz
echo "<form action=/xampp/Website_DataBase/Pvamu_website/quiz/index.php method=post>";
$mysql = "SELECT DISTINCT quiz_name FROM $table";
$mydata = mysql_query($mysql,$con);
while($records = mysql_fetch_array($mydata)){
    $quizname=$records['quiz_name'];

    echo "<input type=radio name=name_quiz value=".$records['quiz_name'].">".$records['quiz_name']."<br>";
}
echo "<input type=submit value=Submit Continue>";
echo "</form>"; 

提交后,它应根据所选的单选按钮显示我的测验

quiz_layout.php

$name = '';
if ( !empty( $_POST['name_quiz'] ) && $_POST['name_quiz'] != '' ) {
    $name = $_POST['name_quiz'];
}

$resource = "SELECT * FROM $table WHERE $table.quiz_name = '$name'";

$mydata=mysql_query($resource);

while($result=mysql_fetch_array($mydata)){
     ?>
<div id="question_<?php echo $result['id'];?>" class='questions'>
<h2 id="question_<?php echo $result['id'];?>"><?php echo $result['id'].".".$result['question_name'];?></h2>
<div class='align'>
<input type="radio" value="1" id='radio1_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'>
<label id='ans1_<?php echo $result['id'];?>' for='1'><?php echo $result['answer1'];?></label>
<br/>
<input type="radio" value="2" id='radio2_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'>
<label id='ans2_<?php echo $result['id'];?>' for='1'><?php echo $result['answer2'];?></label>
<br/>
<input type="radio" value="3" id='radio3_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'>
<label id='ans3_<?php echo $result['id'];?>' for='1'><?php echo $result['answer3'];?></label>
<br/>
<input type="radio" value="4" id='radio4_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'>
<label id='ans4_<?php echo $result['id'];?>' for='1'><?php echo $result['answer4'];?></label>
<input type="radio" checked='checked' value="5" style='display:none' id='radio4_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'>
</div>
<br/>
<input type="button" id='next<?php echo $result['id'];?>' value='Next!' name='question' class='butt'/>
</div>
<?php }?>
</form>

quiz_layout.php设置为一次显示一个问题,但不显示任何内容。帮助并谢谢

2 个答案:

答案 0 :(得分:1)

您是否检查了查询结果或查询中的条件(WHERE $ table.quiz_name ='$ name')? 设置或不设置“$ name”。

答案 1 :(得分:0)

您的HTML无效,您忘记了属性值中的引用。将所有html代码替换为以下内容。

echo "<form action=\"/xampp/Website_DataBase/Pvamu_website/quiz/index.php\" method=\"post\">";