I have a jsfiddle here. What happens is that if you select a radio button and click on "Add Question", it will add a table row showing the radio button you have selected. You can change a selection within the row.
Now what I want to do is that I want to insert the selected radio buttons in each in the database by using the INSERT VALUES method.
So what I want to know is how can I correctly do this so that it $_POST the selected radio buttons for each row and then be able to insert them using INSERT VALUES?
Below is the php code I currently have: (The 'questionText' is the 'Question' column where it actually picks out each row even though I have not included 'questionText' in the jsfiddle and the 'gridValues' is not in the jsfiddle but that is for each textbox value in each row in the 'Options' column, so just imagine there are additional two columns in the table which is 'Question' and 'Options' column)
$i = 0;
$c = count($_POST['gridValues']);
$insertquestion = array();
for($i = 0; $i < $c; $i++ ){
switch ($_POST['gridValues'][$i]){
case "3":
$selected_option = "A-C";
break;
case "4":
$selected_option = "A-D";
break;
default:
$selected_option = "";
break;
}
foreach($_POST['reply'] as $reply) {
switch ($_POST['reply']){
case "Single":
$selected_reply = "Single";
break;
case "Multiple":
$selected_reply = "Multiple";
break;
default:
$selected_reply = "";
break;
}
}
$optionquery = "SELECT OptionId FROM Option_Table WHERE (OptionType = '". mysql_real_escape_string($selected_option)."')";
$optionrs = mysql_query($optionquery);
$optionrecord = mysql_fetch_array($optionrs);
$optionid = $optionrecord['OptionId'];
$replyquery = "SELECT ReplyId FROM Reply WHERE (ReplyType = '". mysql_real_escape_string($selected_reply)."')";
$replyrs = mysql_query($replyquery);
$replyrecord = mysql_fetch_array($replyrs);
$replyid = $replyrecord['ReplyId'];
$insertquestion[] = "'".
mysql_real_escape_string( $_POST['questionText'][$i] ) ."','".
mysql_real_escape_string( $optionid ) ."','".
mysql_real_escape_string( $replyid ) ."'";
}
$questionsql = "INSERT INTO Question (QuestionContent OptionId, ReplyId)
VALUES (" . implode('), (', $insertquestion) . ")";
echo($questionsql);