dennisg001 Posted August 1, 2021 Share Posted August 1, 2021 (edited) 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. Edited August 1, 2021 by dennisg001 Quote Link to comment https://forums.phpfreaks.com/topic/313463-cannot-delete-first-item-from-mi-shopping-cart-php/ Share on other sites More sharing options...
Barand Posted August 1, 2021 Share Posted August 1, 2021 I would check that the query being executed is the one I think is being executed 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';"; echo $SQLREM; exit; } Quote Link to comment https://forums.phpfreaks.com/topic/313463-cannot-delete-first-item-from-mi-shopping-cart-php/#findComment-1588762 Share on other sites More sharing options...
dennisg001 Posted August 1, 2021 Author Share Posted August 1, 2021 I tried that, and I realized that it seems that for that item (first added) the button does not work, it does not send the request for that item.... But I dont understand why, it works for the other items. Quote Link to comment https://forums.phpfreaks.com/topic/313463-cannot-delete-first-item-from-mi-shopping-cart-php/#findComment-1588766 Share on other sites More sharing options...
mac_gyver Posted August 1, 2021 Share Posted August 1, 2021 you probably have some broken markup on the form page (nested forms as an example.) the quickest way to get help would be to post all the code for that page. Quote Link to comment https://forums.phpfreaks.com/topic/313463-cannot-delete-first-item-from-mi-shopping-cart-php/#findComment-1588767 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.