简体   繁体   中英

Cant update first product quantity in Codeigniter Cart

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.

Please help out. 这是我的屏幕截图

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM