目前我正在尝试开发在线购物网站。当我点击添加到购物车按钮时数据没有插入,我在向数据库表插入数据时遇到了困难。任何有专业知识的人都可以告诉我问题在哪里吗?以下是我的代码。
$sqlSelectProdCat1 = mysql_query("select * from tblproduct where prod_cat = 'Hall Package'") or die(mysql_error());
if(mysql_num_rows($sqlSelectProdCat1) >= 1){
$displayProdCat .= '<h2></h2>';
while($getProdInfo1 = mysql_fetch_array($sqlSelectProdCat1)){
$prodNo = $getProdInfo1["prod_no"];
$prodId = $getProdInfo1["pro_id"];
$prodName = $getProdInfo1["prod_name"];
$prodDescri = $getProdInfo1["prod_descri"];
$hallservice= $getProdInfo1["hall_service"];
$prodPrice = $getProdInfo1["prod_price"];
$displayProdCat .= '<form method="post" action="choosepackage.php" /><div class="team-row"><div class="col-md-9 w3ls-team-grids" >
<div class="grid_3 grid_5 wow fadeInUp animated" data-wow-delay=".5s">
<h5>'.$prodName.'</h5>
<h4>RM'.$prodPrice.'</h4>
<h4>(Minimum pax:1000)</h4>
<p>'.$prodDescri.'</p>
</br>
<h6>Service include:</h6>
<p><strong>'.$hallservice.'</strong></p>
<h1>
<a href="cart.php?prodid='.$prodId.'" ><span class="label label-danger">Add to Cart</span></a>
</h1>
<button type="submit" name="order" class="btn btn-success"><i class="icon-plus-sign"></i> Add</button>
<input type="hidden" name="quantity" value="1">
<input type="submit" name="continue" class="button-w3layouts hvr-rectangle-out">
</div>
</div></form>';
if(++$prodCatCtr == 4)
break;
}
<?php
if (isset($_POST['continue'])) {
$quantity = $_POST['quantity'];
$con = mysqli_connect("localhost","root","");
if (!$con){
die("Can not connect:" . mysql_error());
}
mysqli_select_db($con,"mywedding");
mysqli_query($con,"insert into tblorderitem (customerid,productid,productname,productimage,productprice,productquantity,orderstatus) values('$session1','$prodId','$prodName','$prodNo','$prodPrice','$quantity',Pending')");
echo "done";
}
?>
}
答案 0 :(得分:0)
我建议您首先将其拆分为多个文件。然后仔细查看您的表单,因为它没有传递有关您要添加到购物车的产品的任何信息。
另外,将productId插入tblorderitem而不是整个产品及其所有数据更明智。