Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get remove to work on first and not second click

Status
Not open for further replies.

mancroft

Programmer
Joined
Oct 26, 2002
Messages
267
Location
GB
I am deleting an item from a shopping cart by using:



Code:
<a href=&quot;ShoppingBag.php?removeitem=<?php echo $row[&quot;cartId&quot;]; ?>&quot;><img src=&quot;Del.jpg&quot;></a>



in conjunction with:



Code:
if (!empty($_GET['removeitem'])) { 
RemoveItem($_GET['removeitem']); 
}



 function RemoveItem($cartId)
 {
  global $dbServer, $dbUser, $dbPass, $dbName;

  // Get a connection to the database
  $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName) or die(mysql_error());
  
  mysql_query(&quot;delete from cart where cookieId = '&quot; . GetCartId() . &quot;' and cartId = $cartId&quot;) or die(mysql_error());
 }



which works BUT it only deletes if you click on the remove image file TWICE.



Is there a way to get this to work on the first click?



Thanks.
 
could it be that you are merely seeing the cached page in the browser? check the db after the button is clicked once and see if the data is still present.

also try echoing out the sql statement before execution to see if it is correct

maybe change the code to this:

Code:
function RemoveItem($cartId)
                          {
                           global $dbServer, $dbUser, $dbPass, $dbName;

                           // Get a connection to the database
                           $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName) or die(mysql_error());
                           
                          $sql=&quot;delete from cart where cookieId = '&quot; . GetCartId() . &quot;' and cartId = $cartId&quot;) 
                          
                         echo $sql;  
                       
                          $result=mysql_query($sql) or die(mysql_error());
                          }

Bastien

cat, the other other white meat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top