简体   繁体   English

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

[英]How to insert session stored multiple items into database all multiple values using session id in PHP?

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不要将$_POST$_SESSION混淆
  • DO NOT use mysql use mysqli or for extra protection against sql injection, use PDO .不要使用mysql使用mysqli或为了防止 sql 注入的额外保护,请使用PDO Here a useful link to learn about it http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers这里有一个有用的链接来了解它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.如果它是您尝试编码的购物车演示,请不要使用表单中提交的price金额。 Always validate it against a value stored on the database.始终根据存储在数据库中的值对其进行验证。

Good Luck and read as much as you can.祝你好运,尽可能多地阅读。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM