I am trying to insert an array in database but have no luck. Here is what I tried.
I am getting data from a form using the post method.
if(isset($_POST['submit'])){
$type = $_POST['type'];
$color = $_POST['color'];
$thicknes = $_POST['thicknes'];
$fill = $_POST['fill'];
$thickness_2 = $_POST['thickness_2'];
$quantity = $_POST['quantity'];
$email = $_POST['email'];
}
This is dump for each variable
var_dump($type) //outputs -> array(3) { [0]=> string(21) "VALUE1" [1]=> string(13) "VALUE2" [2]=> string(21) "VALUE3" }
var_dump($color) //outputs -> string(9) "#TEST1" [1]=> string(9) "#TEST2" [2]=> string(9) "#TEST3" }
var_dump($thicknes) //outputs -> string(2) "40" [1]=> string(2) "30" [2]=> string(2) "30" }
var_dump($fill) //outputs -> string(3) "55" [1]=> string(3) "66" [2]=> string(3) "77" }
var_dump($thickness_2) //outputs -> string(3) "0.4" [1]=> string(3) "0.3" [2]=> string(3) "0.3" }
var_dump($quantity) //outputs -> string(3) "500" [1]=> string(3) "555" [2]=> string(3) "999" }
var_dump($email) //outputs -> string(13) "[email protected]" }
}
My database
ID | TYPE | COLOR | FILL | THICNKES_2 | QUANTITY | EMAIL
The first transaction should be, the first element from every array. The second should be the second element from every array ...
1 | VALUE1 | TEST1 | 40 | 55 | 500 | [email protected]
Email should be the same for all rows being inserted.
I was trying to insert it by creating a nested foreach, but it doesnt work. It inserts only one row.
foreach($type as $t){
foreach($color as $c){
foreach($thicknesas $tt){
foreach($fill as $f){
foreach($quantity as $q){
foreach($emailas $e){
// query
}
}
}
}
}
}