Hi, I am making a shopping cart and I have a problem. My code to remove the items from the cart works except for the first added item; I can delete all but that one.
This is the form to remove the items.
<form class="col-md-12" method="POST" action="" id="formremove">
<input type="hidden" name="id_prod" value="<?php echo $row['id_producto'] ?>">
<input type="submit" name="btn-remove" class="btn btn-info btn-sm" id="remove" value="X">
</form>
And this is the php
if ($_POST['btn-remove']) {
$id_user=$_SESSION['id_user'];
$id_prod = $_POST['id_prod'];
$SQLREM = "DELETE FROM `carrito` WHERE id_user='$id_user' and id_producto='$id_prod';";
if (mysqli_query($conn, $SQLREM)) {
echo '<script> alert("Ok"); window.location="/CBA/WAUW/cart.php"</script>';
} else {
echo '<script> alert("Error"); window.location="/CBA/WAUW/cart.php"</script>';
};
}
The connection to the database works fine; as I said before, it deletes everything but the first item added.
I would be very grateful for any help.