Im trying to create a table where it would give the list of items then the user can tick the items that they want the input the number of items they want.
<table name="item_orders">
<thead>
<tr>
<th></th>
<th>Item</th>
<th>Price</th>
<th>Quantity</th>
</tr>
</thead>
<?php
$list=getItemList($connect);
while($row=mysqli_fetch_assoc($list)){
?>
<tr>
<td><input type="checkbox" name="check_list[]" value="<?=$row['id']?>"/></td>
<td><?=$row['item']?></td>
<td><?=$row['price']?></td>
<td><input type="text" placeholder="How Many" name="howmany"/></td>
</tr>
<?php
}
?>
</table>
Then I would save it using this code
if(!empty($_POST['check_list'])) {
foreach($_POST['check_list'] as $check) {
$listy = getList($connect, $check) -> fetch_assoc();
$totalamount = $listy['price'] * $howmany;
addBalanceDB($connect, $userID, $listy['item'], $totalamount, null);
}
}
The problem is if the user would select 2 items like (dog food $200) and (cat food $250) then puts a quantity of 5 for the dog food and 10 for the cat food. It would only get the 10 value. Making dog food $2000 instead of just $1000
Aucun commentaire:
Enregistrer un commentaire