tenar Posted March 14, 2013 Share Posted March 14, 2013 Hi, sorry for bumping this thread. I have a question regarding your code. I'm pretty new to any kind of coding. In this line: <input type="radio" name="answer[<?php echo $result['id'] ?>]" value="A"> <?php echo $result['answerA']; ?> <br> what is the value assigned to the name in the end. name="answer" or name="answer$id" or something else. Link to comment https://forums.phpfreaks.com/topic/275659-split-phpmysql-multiple-choice-quiz-logic/ Share on other sites More sharing options...
ignace Posted March 14, 2013 Share Posted March 14, 2013 It's name="answer[1]" this way when the form is posted you get $_POST['answer'] to be an array. For more information: http://www.php.net/manual/en/faq.html.php#faq.html.arrays Link to comment https://forums.phpfreaks.com/topic/275659-split-phpmysql-multiple-choice-quiz-logic/#findComment-1418620 Share on other sites More sharing options...
Barand Posted March 14, 2013 Share Posted March 14, 2013 Names would look like answer[$id] eg <form action="" method="get"> Q1. Do you know which?<br> <input type="radio" name="answer[1]" value="A">A - Answer A<br> <input type="radio" name="answer[1]" value="B">B - Answer B<br> <input type="radio" name="answer[1]" value="C">C - Answer C<br> <input type="radio" name="answer[1]" value="D">D - Answer D<br> <br><br> Q2. What is the answer?<br> <input type="radio" name="answer[2]" value="A">A - Answer A<br> <input type="radio" name="answer[2]" value="B">B - Answer B<br> <input type="radio" name="answer[2]" value="C">C - Answer C<br> <input type="radio" name="answer[2]" value="D">D - Answer D<br> <br><br> <input type="submit" value="Submit" name="btnSubmmit"> </form> So when posted would look like this (depending on the answers selected) Array ( [answer] => Array ( [1] => B [2] => D ) [btnSubmmit] => Submit ) hope that helps Link to comment https://forums.phpfreaks.com/topic/275659-split-phpmysql-multiple-choice-quiz-logic/#findComment-1418633 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.