buy now button-php-add to cart program
<p>i am doing an add to cart.everything is going good.but when i am trying to store the data from the session 2d array into the database it is not happening properly i.e. the last product's id and qty is getting stored only.</p>

<p>this is the page which is used to store the data in database</p>

<pre><code>&lt;?php
session_start();
echo "&lt;pre&gt;";
$value=$_SESSION['cart'];
foreach ($_SESSION['cart'] as $item) {
   // echo 'p_id: ', $item['id'], '&lt;br /&gt;';
   // echo 'p_size: ', $item['p_size'], '&lt;br /&gt;';
    //echo 'p_qty: ', $item['qty'], '&lt;br /&gt;&lt;br /&gt;';
}
//print_r($value);
echo"done";
echo $address=$_GET['add']; 
 echo "&lt;br&gt;";
 echo $con=$_GET['cont']; 
 echo "&lt;br&gt;";
 echo $mail=$_GET['mail'];
 echo "&lt;br&gt;";
 echo $pay=$_GET['mode'];
 echo "&lt;br&gt;";
 echo $total=$_GET['total'];
 echo "&lt;br&gt;";

 //echo "".$_SESSION['cart'];
 //echo $total=$_SESSION['id'];
 //echo $total=$_GET['total'];
 $servername = "localhost";
$username = "root";
$password = "root";
$dbname = "admin1";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn-&gt;connect_error) {
    die("Connection failed: " . $conn-&gt;connect_error);
} 
echo "connected successfully";
echo"&lt;br&gt;";

foreach ($_SESSION['cart'] as $value){
   // print_r($_SESSION);
//print_r($_SESSION['cart']);
    $sql="INSERT INTO orders(total,id,qty,address,cont,mail,mode) values ('".$total."','".$value['id']."','".$value['qty']."','".$address."','".$con."','".$mail."','".$pay."')";

 }
if ($conn-&gt;query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "&lt;br&gt;" . $conn-&gt;error;
}
?&gt; 
</code></pre>