0
我有一个电子商务商店,我正在建立,我需要购买的每件商品都是在数据库中输入的。例如,某人购买了2的数量,我需要重复SQL数据输入,因此它有两个条目。看下面的代码,让我知道我可以如何使用product_qty来实现这一点。PHP重复SQL条目X次数量
if (isset($_SESSION["cart_products"]))
{
$total = 0; //set initial total value
$b = 0; //var for zebra stripe table
foreach ($_SESSION["cart_products"] as $cart_itm)
{
$product_name = $cart_itm["product_name"];
$product_qty = $cart_itm["product_qty"];
$product_price = $cart_itm["product_price"];
$product_code = $cart_itm["product_code"];
$product_color = $cart_itm["product_color"];
$subtotal = ($product_price * $product_qty); //calculate Price x Qty
$name = $_SESSION['firstName']. ' ' .$_SESSION['lastName'];
mysqli_query(
$mysqli,
"INSERT INTO Order_Tickets
(sku, tktproduct, tktprice, purchaser)
VALUES ('$product_code','$product_name','$product_price','$name')"
) or die(mysqli_error());
}
}
你很容易受到[SQL注入攻击(http://bobby-tables.com) –
是的,我知道,这是发展初期,将被添加在一次我有一个正常运作的代码。 – user2044644