如何存储产品记录多个产品? [英] How to store product record more than one products selected?
本文介绍了如何存储产品记录多个产品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经创建了结帐页面。如果我选择多个产品,则记录只存储第二行的一个记录。例如,我选择ABC和XYZ产品存储在数据库中;但只存储在数据库XYZ产品中。下面我给出了我试过的代码。
我尝试过:
这是我在数据库代码中获取的数据。
Hi, I have created checkout page. If i select more than one product, then record store only one record of second row. For example i select ABC and XYZ product to store in database; but only store in database XYZ product. Below i given code what i tried.
What I have tried:
Here is my data fetched in database code.
<form id="order_pro" action="" method="post">
<?php
foreach ($_SESSION['productinfo'] as $productinfo) {
?>
<div class="row">
<input type="text" name="pro_name" value="<?php echo $productinfo['pro_name'];?>"/>
<input type="text" name="pro_qua" value="<?php echo $productinfo['pro_qua'];?>"/>
<input type="text" name="pro_price" value="<?php echo number_format($productinfo['pro_prices'] * $productinfo['pro_qua'],2); ?>"/>
</div>
<div class="row">
<button type="button" class="btn btn-primary next-step button_checkout">Save and continue</button>
</div>
<?php
}
?>
</form>
这是商店数据代码:
Here is store data code:
<?php
require_once '../admin/includes/db_connect.php';
$pro_name = $_POST["pro_name"];
$pro_qua = $_POST["pro_qua"];
$pro_price = $_POST['pro_price'];
$name = $_POST["name"];
$mobile = $_POST["mobile"];
$email = $_POST["email"];
$address = $_POST["address"];
$city = $_POST["city"];
$pin = $_POST["pin"];
if( empty($name)|| empty($mobile)|| empty($email)|| empty($address) || empty($city) || empty($pin)){
echo '
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
Warning! Please fill all mandatory fields.
</div>
';
}
else{
$result=mysqli_query($conn, "INSERT INTO wm_orders(pro_name, pro_qua, pro_price, name, mobile, email, address, city, pin, status) VALUES ('$pro_name','$pro_qua','$pro_price','$name','$mobile','$email','$address','$city','$pin','pending')")or die("Could not insert data: " .mysqli_error($conn));
echo 'data store in database';
}
?>
推荐答案
_SESSION ['productinfo'] as
_SESSION['productinfo'] as
productinfo){
?>
< div class =row>
< input type =textname =pro_namevalue =<?php echo
productinfo) { ?> <div class="row"> <input type="text" name="pro_name" value="<?php echo
productinfo ['pro_name'];?>/>
< input type =textname =pro_quavalue =<?php echo
productinfo['pro_name'];?>"/> <input type="text" name="pro_qua" value="<?php echo
这篇关于如何存储产品记录多个产品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文