简体   繁体   English

无法更新 Codeigniter 购物车中的第一个产品数量

[英]Cant update first product quantity in Codeigniter Cart

I cant seem to update my first product quantity in my Cart on Codeigniter.我似乎无法在 Codeigniter 上更新我的购物车中的第一个产品数量。

Heres the cart.php code:这是购物车。php 代码:

<?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:这是我的 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.所以我可以为其他产品更新它只是第一个,当我按下更新按钮时,它甚至似乎不是 go 到我的更新 function。

Please help out.请帮忙。 这是我的屏幕截图

Found the solution to my problem, the problem was that i actually embeded the updatequantity form inside a form.找到了我的问题的解决方案,问题是我实际上将 updatequantity 表单嵌入到表单中。

Found the solution here: https://www.experts-exchange.com/questions/28410855/Button-in-first-row-of-html-table-does-not-work.html在这里找到解决方案: https://www.experts-exchange.com/questions/28410855/Button-in-first-row-of-html-table-does-not-work.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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