Here is an array from the print_r($_POST)
Array
(
[january] => Array
(
[0] => 10
[1] => 20
[2] => 5
)
[february] => Array
(
[0] => 9
[1] => 8
[2] => 10
)
[march] => Array
(
[0] => 2
[1] => 5
[2] => 6
)
)
Loop for $_POST.
$data = array();
foreach ($_POST as $key => $value) {
$data[] = $value;
}
Statement
INSERT INTO table (january,february,march) VALUES (".implode(", ", $data).")
With this current array how do I make a correct statement? I want to store the data something like this
id january february march
--------------------------
1 10 9 2
2 20 8 5
3 5 10 6
Do it like this:
I have put an
intvalin the code to apply some “basic security” because you should never insert users data unfiltered in your database. Inform yourself about prepared statements and mysql escaping, please ;).