I have an array sent by $ _POST:
array(4) {
["gabarito"]=> string(1) "4"
["resposta1"]=> string(1) "A"
["resposta2"]=> string(1) "B"
["resposta3"]=> string(1) "A"
}
I need to get this information to do an INSERT in MYSQL, but I do not know how to get the $ _POST name (for example: "template"). The end result should be:
(gabarito, resposta1, resposta2, resposta3)
values
(4,A,B,A)
Given that this array is variable, it can have 4 items, 10, 50, several, so it would need to be dynamically
What I thought was the option below, but I do not know how to get the name of $ _POST (is that how it talks? I'm still a beginner, in $ _POST ['answer1'] the answer1 is name? parameter?)
I did this:
foreach($_POST as $resposta){
$resposta.=',';
$respostas .= $resposta;
}
echo '('.$respostas.')';
Then this results in (4, A, B, A,)