This is my 3 dimensional array.
My $_POST array. These are the values
$_POST = Array (
[9] => Array ( [student_id] => 9 [subject_id] => 6 [class_id] => 2 [mark_obtained] => 40 [mark_obtainable] => 100 )
[10] => Array ( [student_id] => 10 [subject_id] => 6 [class_id] => 2 [mark_obtained] => 52 [mark_obtainable] => 100 )
[11] => Array ( [student_id] => 11 [subject_id] => 6 [class_id] => 2 [mark_obtained] => 30 [mark_obtainable] => 100 )
[12] => Array ( [student_id] => 12 [subject_id] => 6 [class_id] => 2 [mark_obtained] => 68 [mark_obtainable] => 100 ) )
How do i loop through it and submit each of the array into the database?
My column names are the keys. "student_id
, subject_id
, class_id
, mark_obtained
, mark_obtainable
".
I am trying this but i keep getting duplicate entries.`foreach ($_POST as $i => $values1) {
foreach ($values1 as $key => $value) {
$columns = implode(", ",array_keys($values1));
$values = implode(", ", $values1);
$columns = $columns
$sql = "INSERT INTO `daily_report`($columns) VALUES ($values)";
if ($conn->multi_query($sql) === TRUE) {
echo "New records created successfully <br>";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}