2016-08-14 5 views
0

Ich möchte, dass Update-Schaltfläche in diesem Feld sein sollte, die ich wähle.Aber es erscheint nur in der ersten Zeile und aktualisiert für die erste Zeile Menge Feld.Aktualisiere Menge in Warenkorb Tabelle

<form action="cart.php?action=update" method="post"> 

<table> 
<tr> 
    <th colspan="2">ITEM</th> 
    <th>QUANTITY</th> 
    <th>PRICE</th> 
    <th>SUBTOTAL</th> 
    <th>REMOVE</th> 

</tr> 
<?php 
     $query = "select * from cart where customer_id='$user' "; 
     $result = mysqli_query($con,$query);$b = 0;$c = 0; 
     while($row = mysqli_fetch_array($result)) 
     { 
       $productid = $row['product_id']; 
       $query2 = "select * from product where product_id='$productid'"; 
       $result2 = mysqli_query($con,$query2); 
       while($row2=mysqli_fetch_array($result2)) 
       { 
?> 
    <tr> 

     <td rowspan="3"><img src="upload/<?php echo $row2['pimage']; ?>" height="50px" width="50px"></td> 
     <td rowspan="3"><?php echo $row2['pname']; ?></td> 
     <td rowspan="3"> 

     <input tpe="text" name="newqty" value="<?php echo $qty = $row['quantity']; ?>" onkeypress="showsubmit()"> 
     <input style="visibility:hidden;width:80px;border-radius:10px;background-color:green;border:none;padding:5px;color:white;" type="submit" name="sub1" id="sub1" value="UPDATE"> 
     <input type="hidden" name="hidcartid" value="<?php echo $row['cart_id'] ?>"/> 
     <input type="hidden" name="hidproductid" value="<?php echo $row['product_id']; ?>"/> 
     <script> 
      function showsubmit() 
      { 

       document.getElementById("sub1").style.visibility = "visible"; 
      } 

     </script> 


     </td> 

     <td>Price:<?php echo $sp = $row2['psellingprice']; ?></td> 
     <?php 
       $total = $sp * $qty; 
     ?> 
     <td rowspan="3"> 
     <?php 
      echo $t = $total; 
      $b = $b + $t; 


     ?></td> 
     <td rowspan="3"><a href="cart.php?action=delete&cid=<?php echo $row['cart_id']; ?>"">REMOVE</a></td> 
    </tr> 
    <?php 
     $action = (array_key_exists('action', $_REQUEST) ? $_REQUEST['action'] : ""); 

     if($action =="delete") 
     { 

      deletecart($_REQUEST['cid']); 

     } 
     if($action=="update") 
     { 
      echo "update function called"; 
      updatecart(); 
      echo "update function executed"; 
     } 

    ?> 
    <tr> 
     <td>Selling Price:<?php echo $p = $row2['pprice']; ?></td> 

    </tr> 
    <tr> 
     <td>You Saved: 
     <?php 

      $d = $row2['pdiscount']; 
      $s = ($p*$d)/100; 
      echo $q = $s * $qty; 
        $c = $c + $q; 


     ?>&nbsp; rs.</td> 
    </tr> 
<?php 
       } 
     } 

?> 
</table> 

und

<?php 

function deletecart($cartid) 
{ 
    include 'connection.php'; 

    $sql1="delete from cart where cart_id=$cartid"; 
    $executequery = mysqli_query($con,$sql1); 
    header('location:cart.php'); 
} 
function updatecart() 
{ 
    include 'connection.php'; 
    $cartId  = $_POST['hidcartid']; 
    $productId = $_POST['hidproductid']; 
    $newqty = $_POST['newqty']; 

    echo("inside update function"); 


      // update product quantity 
     $sql = "UPDATE cart 
       SET quantity = $newqty 
       WHERE cart_id = $cartId"; 


     mysqli_query($con,$sql); 
     header('location:cart.php'); 
    }?> 

Für Reihe cart2.php onw ist alles fine.But für row2 Update-Button erscheint in row1 und schon gar nicht zu aktualisieren.

Antwort

0
<input tpe="text" name="newqty" value="<?php echo $qty = $row['quantity']; ?>" onkeypress="showsubmit(<?php echo $row['cart_id'] ?>)"> 

<input style="visibility:hidden;width:80px;border-radius:10px;background-color:green;border:none;padding:5px;color:white;" 
       type="submit" 
       name="sub_<?php echo $row['cart_id'] ?>" 
       id="sub_<?php echo $row['cart_id'] ?>" 
       value="UPDATE"> 

<script> 
    function showsubmit(id) 
    { 
       document.getElementById("sub_"+id).style.visibility ="visible"; 
    } 
</script> 
+0

danke :) Es hat funktioniert. – sneha

Verwandte Themen