[英]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:给你一些提示:
$_POST
with $_SESSION
$_POST
与$_SESSION
混淆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_Developersprice
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.