Jump to content

Cannot delete first item from mi shopping cart PHP


dennisg001

Recommended Posts

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 by dennisg001
Link to comment
Share on other sites

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;
}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.