I have a page where the user is adding answers to a question they have written. The page has up to four text area boxes( depending on how many answers they choose to supply to the question) and a checkbox under each answer to signify if the answer is correct or not( the questions can have one or more correct answers).
When the page is submitted I dumped out the $_POST array using print_r and this is what i get
Array
(
[0] => May
[quest] => Array ( [0] => 1 [1] => 2 [2] => 3 )
[1] => June
[2] => July
[3] => December
)
The arrays that have an integer name are the answers and the quest array holds the correct answers.
So in the above the answers are May,June,July and December, and the correct answers are 1,2 and 3.
I need to put this into a MySQL database. I have been trying various things. Here is the latest.
Code: Select all
foreach ($_POST as $value)
{
if (is_int(array_key($value)))
{
$sql = "INSERT INTO answers set
question = '$value[0]',
question_id ='$question_id'";
if (!mysqli_query($link, $sql))
{
$error = 'Error inserting answer into answers '
.mysqli_error($link);
include 'error.html.php';
exit();
}
}
}
include 'error.html.php';
exit();
}