如何使用PHP中的会话ID将会话存储的多个项目插入数据库所有多个值?

My shopping cart items stored in session but I want store all items in database.

<?php
if (isset($_POST['order'])) {
     $member_id = $_POST['member_id'];
    $item_id = $_POST['item_id'];
    $item_name = $_POST['item_name'];
    $item_price = $_POST['item_price'];
    $item_qty = $_POST['item_qty'];
     $total = $_POST['total'];

 mysql_select_db('shoppingcartdemo',   mysql_connect('localhost','root',''))or die(mysql_error());
    mysql_query("insert into ordernew (id,item_id,item_name,item_price,item_qty,total,status,member_id) values('','$item_id','$item_name','$item_price','$item_qty','$total','Delivered','$member_id')") or die(mysql_query);

header('location:payment.php'); 


}
?>

A few tips for you:

  • DO NOT confuse $_POST with $_SESSION
  • DO NOT use mysql use mysqli or for extra protection against sql injection, use PDO. Here a useful link to learn about it http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers
  • If it is a shopping cart demo you are trying to code, do not use the price amount submitted in a form. Always validate it against a value stored on the database.

Good Luck and read as much as you can.