doulai8405 2017-01-09 12:43
浏览 49

如何使用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'); 


}
?>
  • 写回答

1条回答 默认 最新

  • douzhang1299 2017-01-09 13:07
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大