I am working on cake website where user can add cakes in their cart. Then, their cart summary will be displayed in this page.For now, i could only generate summary of cart from database. I need to allow user to click on desired delete button and be able to delete the respective cart row from database.
Php code
// To display the summary
$pick = "SELECT bname,quantity,price,sum FROM cart WHERE user_id LIKE '$search'";
$result1 = mysqli_query($conn, $pick);
$counting = 1;
if (mysqli_num_rows($result1) > 0) {
echo "<table align='center' class='summarytbl'>";
echo "<tr><th>No</th><th>Book Title</th><th>Price</th><th>Quantity</th><th>Total Price</th><th>Delete Order</th></tr>";
while($row = mysqli_fetch_assoc($result1)) {
echo "<tr><td>".$counting."</td><td>".$row['bname']."</td><td>".$row['price']."</td><td>".$row['quantity']."</td><td>".$row['sum']."</td><td><button type='button' class='delete' name=".$row['bname']." value=".$row['quantity'].">Delete</button></td></tr>";
$counting++;
}
echo"</table><br/><br/><br/>";
echo "<table align='center' class='new'>";
echo "<tr><td>Total Price</td><td>".$total."</td></tr>";
echo "<tr><td>Discount</td><td>".$discount."</td></tr>";
echo "<tr><td>Postage</td><td>".$postage."</td></tr>";
echo "<tr><td><b>Nett Price</b></td><td><b>".$nett."</b></td></tr>";
echo"</table>";
}
i was hoping to use this statement to get button's value(quantity) and name(cake name) to delete row from table. But, it is not working. Please help.Thank you.
if(isset($_POST['delete']))
{
$command = "DELETE FROM cart WHERE bname= ".$row['bname']." AND quantity=".$row['quantity'];
mysqli_query($conn,$command);
}