I cant seem to update my first product quantity in my Cart on Codeigniter.
Heres the cart.php code:
<?php
$cartdata = $this->cart->contents();
foreach ($cartdata as $data):
?>
<form method="POST" action="<?php echo base_url();?>wholesaler/updatequantity/">
<tr>
<td class="product__thumbnail">
<a href="#">
<img src="<?php echo base_url().'uploads/products/'.$data['image'];?>" alt="">
</a>
</td>
<input class="form-control" name="rowid" value="<?php echo $data['rowid'];?>" type="hidden">
<td class="product__name">
<a href="#"><?php echo $data['name']; ?></a>
<br><br>
<small><?php echo $data['sellername']; ?></small>
</td>
<td class="product__price">
<div class="price">
<span class="new__price">RWF <?php echo $data['price']; ?></span>
</div>
</td>
<td class="product__quantity">
<div class="input-counter">
<div>
<span class="minus-btn" id="decrease" onclick="decreaseValue()">
<img src="https://img.icons8.com/android/24/000000/minus.png"/>
</span>
<input type="number" id="number" min="0" name="qty" placeholder="<?php echo $data['qty'];?>" class="counter-btn" />
<span class="plus-btn" id="increase" onclick="increaseValue()">
<img src="https://img.icons8.com/android/24/000000/plus.png"/>
</span>
</div>
</div>
</td>
<td>
<button type="submit" class="btn btn-secondary btn-sm">Update Quantity</button>
</td>
</form>
<td class="product__subtotal">
<div class="price">
<span class="new__price">RWF <?php echo $data['subtotal']; ?></span>
</div>
<a href="<?php echo base_url().'wholesaler/deletecart/'.$data['rowid'];?>" class="remove__cart-item">
<svg>
<img src="https://img.icons8.com/ios-filled/24/000000/delete-forever.png"/>
</svg>
</a>
</td>
</tr>
<?php endforeach ;?>
Here is my controller:
function updatequantity(){
$data = array(
'rowid' => $this->input->post('rowid'),
'qty' => $this->input->post('qty'),
);
$this->cart->update($data);
$this->load->view('wholesale/cart');
}
So i can update for other products its just the first one, it even seems not to go to my update function when i press the update button.
Found the solution to my problem, the problem was that i actually embeded the updatequantity form inside a form.
Found the solution here: https://www.experts-exchange.com/questions/28410855/Button-in-first-row-of-html-table-does-not-work.html