i'm newbie in PHP, and sorry for my English. I had read all the questions about this topic in this forum, but i still cant find the solution for my PHP. I have 2 session here, first to save data person, and second to save cart. Here my session structure
<?php
$id_pers person = $_SESSION['person'] ; //its contain just id
//for second $_SESSION['cart'] structure when i print_r is like this
Array (
[0] => Array (
[item_id] => 4
[item_name] => Notebook
[item_qty] => 1
[price] => 750
)
[1] => Array (
[item_id] => 5
[item_name] => Keyboard
[item_qty] => 1
[price] => 70
)
[2] => Array (
[item_id] => 6
[item_name] => Mouse
[item_qty] => 1
[price] => 50
)
)
?>
The problem is when i save array into database its just one array is saved, the other array cant save into database. Here my insert function what i wrote from watching video tutorial:
<?php
function save($array, $connect){
if(is_array($array)){
$id_person = $_SESSION['person'];
foreach($array as $row => $value) {
$item_id = mysqli_real_escape_string($connect, $value['item_id'];
$item_qty = mysqli_real_escape_string($connect, $value['item_qty'];
$sql = "INSERT INTO tbl_order(id_person,item_id,qty) VALUES ('".$id_person."','".$item_id."','".$item_qty."')";
mysqli_query ($connect, $sql);
}
}
}
save($_SESSION['cart'], $ connect);
?>
Please tell me where is my mistake on my script for inserting data array into table. Thanks :)