作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚创建了一个数量下拉框,唯一的问题是当点击添加购物车按钮时,下拉框的数量或所选值没有插入到带有数量列的表名购物车中,请帮助..下面是代码来自functions.php 和 product.php
<div id="products_box">
<?php
$get_pro = "select * from products ";
$run_pro = mysqli_query($con, $get_pro);
while($row_pro=mysqli_fetch_array($run_pro)){
$pro_id = $row_pro['product_id'];
$pro_cat = $row_pro['product_cat'];
$pro_brand = $row_pro['product_brand'];
$pro_title = $row_pro['product_title'];
$pro_price = $row_pro['product_price'];
$pro_image = $row_pro['product_image'];
$pro_qty = $row_pro['product_qty'];
echo "
<div id='single_product'>
<h4>$pro_title</h4>
<img src='admin_area/product_images/$pro_image' width='180' height='80' />
<p><b> Php $pro_price.00</b></p>
<a href='details.php?pro_id=$pro_id' style='float:left;'>Details</a>
<select name='quantity'>";
for($i=1;$i<=$pro_qty;$i++) {
echo "<option value=$i>$i</option>";
}
echo "</select>
<a href='index.php'?pro_id=$pro_id'><button style='float:right'>Add to Cart</button></a>
</div>
";
}
?>
</div>
function cart(){
if(isset($_GET['add_cart'])){
global $con;
$ip = getIp();
$pro_id = $_GET['add_cart'];
$pro_qty = $_POST['quantity'];
$check_pro = "select * from cart where ip_add='$ip' AND p_id='$pro_id'";
$run_check = mysqli_query($con, $check_pro);
if(mysqli_num_rows($run_check)>0){
echo ""; //refresh or do nothing
}
else {
$insert_pro = "insert into cart(p_id,ip_add,qty) values ('$pro_id','$ip','$pro_qty')";
$run_pro = mysqli_query($con, $insert_pro);
echo "<script>window.open('index.php','_self')</script>";
}
}
最佳答案
你能试试这个吗
<div id="products_box">
<?php
$get_pro = "select * from products ";
$run_pro = mysqli_query($con, $get_pro);
while($row_pro=mysqli_fetch_array($run_pro)){
$pro_id = $row_pro['product_id'];
$pro_cat = $row_pro['product_cat'];
$pro_brand = $row_pro['product_brand'];
$pro_title = $row_pro['product_title'];
$pro_price = $row_pro['product_price'];
$pro_image = $row_pro['product_image'];
$pro_qty = $row_pro['product_qty'];
echo "
<form method='post' action='index.php'>
<input type='hidden' value= '".$pro_id."' name ='pro_id' />
<div id='single_product'>
<h4>$pro_title</h4>
<img src='admin_area/product_images/$pro_image' width='180' height='80' />
<p><b> Php $pro_price.00</b></p>
<a href='details.php?pro_id=$pro_id' style='float:left;'>Details</a>
<select name='quantity'>";
for($i=1;$i<=$pro_qty;$i++) {
echo "<option value=$i>$i</option>";
}
echo "</select>
<input type='submit' name='add' value='Add to Cart'>
</div>
</form>
";
}
?>
</div>
function cart(){
if(isset($_GET['add_cart'])){
global $con;
$ip = getIp();
$pro_id = $_POST['pro_id'];
$pro_qty = $_POST['quantity'];
$check_pro = "select * from cart where ip_add='$ip' AND p_id='$pro_id'";
$run_check = mysqli_query($con, $check_pro);
if(mysqli_num_rows($run_check)>0){
echo ""; //refresh or do nothing
}
else {
$insert_pro = "insert into cart(p_id,ip_add,qty) values ('$pro_id','$ip','$pro_qty')";
$run_pro = mysqli_query($con, $insert_pro);
echo "<script>window.open('index.php','_self')</script>";
}
}
}
关于php - 如何获取所选下拉框的值并插入数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29205150/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!