I have a form with several radio buttons grouped by the same name, and those radio buttons are generated dinamically, there are 20 in total, but it will only be submitted 4 each time. Each radio button group as an ID as name of the group. When post the form to PHP (using jQuery Serialize) I get something like this:
1=3&2=6&4=9&7=2
I need to get the values of each parameter, in this case 1, 2, 4 and 7 and also to know which was the fields submitted (in this case the field 1, 2, 4 and 7 was submitted)
I did something like this, but not working:
for ($c = 1; $c <= 20; $c++){
if (isset($_GET[$c])){
$question_id = $c;
$answer_score = $_GET[$c];
echo $answer_score;
$gravar = "INSERT INTO iMood_ColabsQuestionAnswers (colab_id, answer_id, score) VALUES (?, ?, ?)";
/* Set parameter values. */
$valores = array($user, $question_id, $answer_score);
echo $valores.'<br />';
/* Prepare and execute the query. */
$inserirResposta = sqlsrv_query( $conn, $gravar, $valores);
sqlsrv_free_stmt($inserirRespota);
sqlsrv_close($conn);
}
}
Can’t find a solution for this, because the above solution, doesn’t see any record and if use
$_GET['$c'];
It returns an error in SQL query, saying that found an unexpected (.
How are you submitting that serialized string from jquery?
Doing something like
would lead to the problem you’re having. This would submit a complete string containing those “query” variables, but do it without an associated field name, so PHP will NOT pick up the fact that this string contains individual key/value pairs.
However, using
will let things work in PHP properly, and you’d get at the data like this: