我已经更多地搜索了这个主题解决方案"如何将多个项目插入数据库",但我无法理解。希望有人可以帮助我!
shopping cart
{
while($row=mysqli_fetch_array($res)){
$total=($row['product_price']*$row['quantity']);
$tot = $tot + ($row['product_price']*$row['quantity']);
?>
<tr>
<td align="center"><img src="<?php echo $item['product_image'];?>" width="150px" height="150px" alt=""/></td>
<td><?php echo $row['product_name'];?></td>
<td><?php echo $row['quantity'];?></td>
<td>RM <?php echo $total;?></td>
<td style="text-align:center"><a href="delete_shopping_cart_item.php?id=<?php echo $row["id"];?>" onclick="return confirm('Are you sure you want to delete this item?');">
Remove
</a></td>
</tr>
<?php
}
if(isset($_POST['submit1']))
{
$customer = $_SESSION['login_user'];
$res = mysqli_query($mysqli,"SELECT * FROM shopping_cart where customer ='$customer'");
$row=mysqli_fetch_array($res);
$qty = $row['quantity'];
$product_name = $row['product_name'];
$rname = $_POST['rname'];
$raddress = $_POST['raddress'];
$rcontactno = $_POST['rcontactno'];
$total = $_SESSION['total'] ;
mysqli_query($mysqli,"insert into confirm_order (product_name,quantity,total_price,receiver_name,receiver_address,receiver_contact,customer)
values('$product_name','$qty','$total','$rname','$raddress','$rcontactno','$customer')");
$_SESSION['receiver'] = $rname;
}
}
答案 0 :(得分:0)
试试这个:
while ($row=mysqli_fetch_array($res)) {
$qty = $row['quantity'];
$product_name = $row['product_name'];
$rname = $_POST['rname'];
$raddress = $_POST['raddress'];
$rcontactno = $_POST['rcontactno'];
$total = $_SESSION['total'] ;
mysqli_query($mysqli,"insert into confirm_order (product_name,quantity,total_price,receiver_name,receiver_address,receiver_contact,customer)
values('$product_name','$qty','$total','$rname','$raddress','$rcontactno','$customer')");
}