i have a jsfiddle here . What it does is that when the user clicks on the "Add Question" button, it adds a radio buttons in each row. But what I want to do is use $_POST to post selected radio buttons in each row into the the insertQuestions.php page (action the form takes use to).
So what I want to know is how do I write the $_POST statement to be able to paste checked radio buttons?
UPDATE:
Is this code below correct in terms of finding the ReplyId for the selected radio by using z case statement then a query:
$i = 0;
$c = count($_POST['reply']);
$insertquestion = array();
for($i = 0; $i < $c; $i++ ){
switch ($_POST['reply'][$i]){
case "Single":
$selected_option = "Single";
break;
case "Multiple":
$selected_option = "Multiple";
break;
default:
$selected_option = "";
break;
}
$replyquery = "SELECT ReplyId FROM Reply WHERE (ReplyType = '". mysql_real_escape_string($_POST['reply'])."')";
$replyrs = mysql_query($replyquery);
$replyrecord = mysql_fetch_array($replyrs);
$replyid = $replyrecord['ReplyId'];
All you need to do is when you run your AJAX script. On the process page you would use something like
<?PHP
$reply1 = $_POST['reply1'];
$reply2 = $_POST['reply2'];
however you will want to change the name of the input fields to
name="reply[]"
which will make the posted data an array
UPDATE: The previous is only valid for checkboxes in this case (which there are none) With checkboxes of the same name, is checkbox 1 is checked and then checkbox 2 is checked, you will only get the value of checkbox 2 on the post.
Since reply is the name with a number after for duplicated questions, you can always get all posted variables by just using $_POST
. Doing this will give you an array of ALL posted data
If you want to go through each reply since it is dynamic just do a foreach statement
foreach($_POST as $k=>$v) {
//Run script to process each posted reply
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.