Reputation: 39
I have a page with radio buttons and when submitted it should display go to a quiz_layout.php page. The layout page is should display a quiz only based on the radio button submitted. Can anyone help me? I'm not sure why my data isn't being displayed.
page 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>";
Once submitted it should display my quiz based on the selected radio button
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>
The quiz_layout.php is setup to display one question at a time but nothing is displaying. Help and thank you
Upvotes: 0
Views: 102
Reputation: 166
Have you checked your query result or where condition in query(WHERE $table.quiz_name = '$name')? "$name" is set or not checked it.
Upvotes: 1
Reputation: 1423
Your html is invalid, you forgot quotations in attributes value. Replace all your html code as following.
echo "<form action=\"/xampp/Website_DataBase/Pvamu_website/quiz/index.php\" method=\"post\">";
Upvotes: 0