Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php仅返回上一个产品的所需值_Php_Html_Forms_Input_Cart - Fatal编程技术网

php仅返回上一个产品的所需值

php仅返回上一个产品的所需值,php,html,forms,input,cart,Php,Html,Forms,Input,Cart,当我单击“更新”时,它现在应该向我返回产品ID和所需数量,但它只返回最后一个产品的结果。 当尝试在购物车中的其他产品上执行此操作时,它只返回一个空引号(用于数量)和一个ID号 这是我的密码。cart.php <?php include("functions/functions.php"); ?> <!DOCTYPE html>

当我单击“更新”时,它现在应该向我返回产品ID和所需数量,但它只返回最后一个产品的结果。 当尝试在购物车中的其他产品上执行此操作时,它只返回一个空引号(用于数量)和一个ID号

这是我的密码。cart.php

              <?php


              include("functions/functions.php");


               ?>

              <!DOCTYPE html>
              <html>
                  <head>
                      <meta charset="utf-8">
                      <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.12/css/all.css" integrity="sha384-G0fIWCsCzJIMAVNQPfjH08cyYaUtMwjJwqiRKxxE/rx96Uroj1BtIQ6MLJuheaO9" crossorigin="anonymous">
                      <link type="text/css" rel="stylesheet" href="styles/style.css" />
                      <title>Prodavnica+</title>
                  </head>
                  <body>
                      <div id="header" class="cf">
                          <a href="index.php"><img src="images/logo.png" /></a>
                          <div id="navbar">
                              <ul>
                                  <li>
                                      <a href="index.php"> Home</a>
                                  </li>
                                  <li>
                                      <a href="all_products.php"> Products</a>
                                  </li>
                                  <li>
                                      <a href="customer/my_account.php"> My Account</a>
                                  </li>
                                  <li>
                                      <a href="#"> Sign Up</a>
                                  </li>
                                  <li>
                                      <a href="cart.php"> Shopping Card</a>
                                  </li>
                                  <li>
                                      <a href="#"> Contact Us</a>
                                  </li>
                              </ul>
                          </div> <!-- END navbar -->
                          <div id="search">
                              <form method="get" action="results.php" enctype="multipart/form-data">
                                  <input type="text" name="search_query" placeholder="Search Product" />
                                  <input type="submit" name="search_button" value="Search" />

                              </form>
                          </div>
                      </div> <!-- END header -->
                      <?php cart(); ?>
                      <div id="shop-bar">
                          <p>
                              Total items: <?php totalItems() ?>
                          </p>
                          <p>
                              Total price: <?php totalPrice()?>
                          </p>
                          <a href="cart.php"><i class="fas fa-shopping-cart">   | </i></a>
                          <span> Welcome Guest! </span>

                      </div> <!-- END shop-bar -->
                      <div id="container">

                          <div id="main">

                              <div id="product-box-cart">

                              <form action="" method="post" enctype="multipart/form-data">
                                  <table>

                                          <thead>
                                              <th>Product</th>
                                              <th>Quantity</th>
                                              <th>Remove</th>
                                              <th>Price</th>
                                          </thead>
                                          <tbody>
                                              <?php

                                                  $total = 0;

                                                  global $con;

                                                  $ip = getIp();

                                                  $run_price = mysqli_query($con,"SELECT * FROM cart WHERE ip_add = '$ip'");

                                                  while($row_pro_price = mysqli_fetch_array($run_price)) {

                                                      $pro_id = $row_pro_price['p_id'];
                                                      $pro_qty = $row_pro_price['qty'];

                                                      $run_pro_price2 = mysqli_query($con,"SELECT * FROM products WHERE product_id = '$pro_id'") or die(mysqli_error($con));

                                                      while($row_pro_price2 = mysqli_fetch_array($run_pro_price2)) {

                                                          $pro_price = array($row_pro_price2['product_price']);
                                                          $pro_title = $row_pro_price2['product_title'];
                                                          $product_image = $row_pro_price2['product_image'];
                                                          $single_price = $row_pro_price2['product_price'];



                                                          $pro_price_values = array_sum($pro_price);


                                                          $total += $pro_price_values;





                                              ?>

                                              <tr>
                                          <td>
                                              <h2><?php echo $pro_title ?></h2>
                                              <img src="admin/product_images/<?php echo $product_image;?>">

                                          </td>
                                          <td>
                                              <input type="text" name="qty" placeholder="<?php echo $pro_qty; ?>">
                                              <button type="submit" name="qty_btn" value = "<?php echo $pro_id; ?>"> Update </button>

                                          </td>

                                          <td>
                                              <button type="submit" name="remove" value="<?php echo $pro_id; ?>"> Remove </button>


                                          </td>
                                          <td>
                                              <?php echo "$" . $single_price; ?>
                                          </td>


                                          </tr>

                                          </tbody>


              <?php }} ?>
                                  </table>

                                  <p>
                                  <b>  Total Value: </b>  <?php  echo "$" . $total;?>
                                  </p>
                                  <div id="check-buttons">
                                  <input type="submit" name="continue" value="Continue Shopping" />
                                  <a href="checkout.php"><input type="button" value="Checkout" /></a>


                                </div> <!-- end cHECK BUTONS -->
                              </form>
                              <?php
                              if(isset($_POST['qty_btn'])) {


                                $qty = $_POST['qty'];
                                $qty_id = $_POST['qty_btn'];

                                printf($_POST['qty_btn']);
                                printf($_POST['qty']);

                              }elseif(!isset($_POST['qty_btn'])) {
                                if(isset($_POST['remove'])) {

                                  $remove_id = $_POST['remove'];

                                  var_dump($remove_id);
                                }
                              }

                              ?>

                              </div> <!-- END product box -->

                          </div> <!-- END main -->


                          <div id="side">
                              <div id="side-category">
                                  <h2>Categories</h2>
                                  <hr />
                                  <table id="mw">
                                      <tr>
                                          <?php
                                          getBrands();

                                           ?>
                                      </tr>
                                  </table>

                                  <ul>

                                      <?php
                                      getCats();
                                       ?>

                                  </ul>
                              </div><!-- END side-category-->

                          </div> <!-- END side -->

                      </div> <!--END container -->

                      <div id="footer">
                          <p>&copy; 2018 by Djordje Stamenkovic</p>
                      </div> <!-- END footer -->

                  </body>
              </html>

普罗达夫尼卡+
项目总数:

总价:

欢迎光临! 产品 量 去除 价格
当您有一个
表单时
-所有定义的输入都会发送到下一页,并且可以通过其
名称
访问

如果您现在使用相同的名称定义了更多的字段(这样做是因为您循环了不同的产品),则在提交后将无法访问正确的值

你的结构

<form action>
   while (...) { 
       <input name="qty" value="...">
       <button submit>
   }
</form>
while (...) {
    <form action>        
       <input name="qty" value="...">
       <button submit>
   </form>
}