我想将显示数据产品中的数据插入数据库idk它是怎么做的
此产品是从下面的其他形式显示的
否则我必须通过按钮或表格发送? 像这样将数据添加到数据库
id 名称 数量
1 pd01 2
2 pd03 2
cart.php
if(!empty($_GET["action"])) {
switch($_GET["action"]) {
case "save":
if(!empty($_SESSION["cart_item"])) {
foreach($_SESSION["cart_item"] as $k => $v) {
<!== HERE! i want to insert when get session from button BtnSave
then remove session ==>
}
}
break;
------------------------
<?php
if(isset($_SESSION["cart_item"])){
$total_quantity = 0;
$total_price = 0;
?>
<?php
foreach ($_SESSION["cart_item"] as $item){
$item_price = $item["quantity"]*$item["price"];
?>
<tr>
<td><img src="<?php echo $item["image"]; ?>" class="cart-item-image" /><?php echo $item["name"]; ?></td>
<td><?php echo $item["code"]; ?></td>
<td style="text-align:right;"><?php echo $item["quantity"]; ?></td>
<td style="text-align:right;"><?php echo "$ ".$item["price"]; ?></td>
<td style="text-align:right;"><?php echo "$ ". number_format($item_price,2); ?></td>
<td style="text-align:center;"><a href="index.php?action=remove&code=<?php echo $item["code"]; ?>" class="btnRemoveAction"><img src="icon-delete.png" alt="Remove Item" /></a></td>
</tr>
<?php
$total_quantity += $item["quantity"];
$total_price += ($item["price"]*$item["quantity"]);
}
?>
<td colspan="5"><a id="BtnSave" href="index.php?action=save&code=<?=$item["code"];?>&=<?= $item["name"];?>">Save!</a> </td>
代码是通过“form action=add”提交的,很长idk有必要向您展示
它可以正常添加到表上
我从某处得到这段代码并向左插入数据 提前谢谢你的回答
cart.php
------
<?php
$product_array = $db_handle->runQuery("SELECT * FROM tblproduct ORDER BY id ASC");
if (!empty($product_array)) {
foreach($product_array as $key=>$value){
?>
<div class="product-item">
<form method="post" action="index.php?action=add&code=<?php echo $product_array[$key]["code"]; ?>">
<div class="product-image"><img src="<?php echo $product_array[$key]["image"]; ?>"></div>
<div class="product-tile-footer">
<div class="product-title"><?php echo $product_array[$key]["name"]; ?></div>
<div class="product-price"><?php echo "$".$product_array[$key]["price"]; ?></div>
<div class="cart-action"><input type="text" class="product-quantity" name="quantity" value="1" size="2" /><input type="submit" value="Add to Cart" class="btnAddAction" /></div>
</div>
</form>
</div>
</form>
<?php
}
}
?>