vendredi 28 avril 2017

Answers from Radio buttons and checkboxes to mysql using php

For a survey app which has a combination of radiobuttons and checkboxes. How do I use PHP to insert the selected values to mysql db using php? This is the query for fetching the questions from db:

while($row2 = $result2->fetch_assoc())
{

if($row2["subtype"] =="radio")
{
 echo "<input id = \"radio\" class='radio_input' type=\"radio\" name=answergroup[".$row["PK_QUESTION_ID"].
"] value=".$row2["opt_id"].">".$row2["opt_text"]."</input>";

else if($row2["subtype"] =="checkbox")
{
echo "<input id = \"checkbox\" class='radio_input' type=\"checkbox\" name=answergroup[".$row["PK_QUESTION_ID"].
"] value=".$row2["opt_id"].">".$row2["opt_text"]."</input>";

}
}

I tried using $_POST['answergroup'] for fetching the selected options, but in the case of a checkbox, only one option is being fetched even if there are multiple selections made.




Aucun commentaire:

Enregistrer un commentaire