mo Posted April 16, 2009 Share Posted April 16, 2009 On my cart page I have a delete button next to each item in the cart. The delete button is defined as follows and when clicked, should set the GET variables which should trigger my if statement. However, the page reloads, no GET variables are set and nothing happens. <td class=\"dataListItem\"> <input type=\"image\" class=\"image\" src=\"$img_home/icons/delete.gif\" alt=\"Delete\" name=\"btnDelete\" id=\"btnDelete\" value=\"Delete\" onClick=\"window.location.href='".$_SERVER['PHP_SELF']."?action=remove_item&smid=$strID&itemOption=$strOptions'\"> </td></tr> I tried putting the item variables I need passed on click in the value="" tag but this is always equal to the values for the last item printed in my list. I do not want to add check boxes next to items and have a button at the bottom of the cart page to delete, than loop at the checked boxes and delete items. I would like to have the page reload with the GET variables set. This was working at one point. Any ideas. Quote Link to comment Share on other sites More sharing options...
ober Posted April 16, 2009 Share Posted April 16, 2009 I don't see any opening php tags unless that is done outside of what you've shown us. Show more of the code. Quote Link to comment Share on other sites More sharing options...
mo Posted April 16, 2009 Author Share Posted April 16, 2009 I don't see any opening php tags unless that is done outside of what you've shown us. Show more of the code. Sorry, more code below. <?php require_once './config/global.php'; require_once MY_DIR.'/access.php'; require_once MY_DIR.'/functions.php'; header("Cache-Control: no-cache"); header("Pragma: nocache"); if($_GET["action"] == "remove_item") { RemoveItem($_GET["smid"],$_GET['itemOption']); } echo "<html> <head></head> <body>"; echo "<form id=\"CartForm\" name=\"CartForm\" method=\"post\" action=\"".$_SERVER['PHP_SELF']."\"> <div id=\"DataListForm\">"; echo "<table class=\"dataList\" align=\"center\">"; $q1 = mysql_query("SELECT * FROM `my_cart_table` WHERE `cart_id` = '$FakeID'") or die(mysql_error()); while($ArrayRow = mysql_fetch_array($q1)) { echo "<tr><td class=\"dataListItem\">$strID</td> <td class=\"dataListItem\"> <a href=\"dispmenu.php?storeid=$strStoreId&storename=".urlencode($strStoreName)."\">$strStoreName</a></td> <td class=\"dataListItem\">$strTitle</td> <td class=\"dataListItem\">$strRecipient</td> <td class=\"dataListItem\">$strComments</td> <td class=\"dataListItem\">$strProdSize</td> <td class=\"dataListItem\"> <input id=\"qID[]\" name=\"qID[]\" type=\"text\" size=\"5\" value=\"$strQty\" maxlength=\"5\"> <input type=\"hidden\" class=\"hidden\" id=\"pid[]\" name=\"pid[]\" value=\"$strID\"> <input type=\"hidden\" class=\"hidden\" id=\"optionStr[]\" name=\"optionStr[]\" value=\"$strOptions\"> </td> <td class=\"dataListItem\">$strPrice</td> <td class=\"dataListItem\" colspan=\"2\">$strTotal</td> <td class=\"dataListItem\"> <input type=\"image\" class=\"image\" src=\"$img_home/icons/delete.gif\" alt=\"Delete\" name=\"btnDelete\" id=\"btnDelete\" value=\"Delete\" onClick=\"window.location.href='".$_SERVER['PHP_SELF']."?action=remove_item&smid=$strID&itemOption=$strOptions'\"> </td></tr>"; } echo "</table> </div> </form> </body> </html>"; ?> Quote Link to comment Share on other sites More sharing options...
ober Posted April 16, 2009 Share Posted April 16, 2009 Do you have a live version and/or have you viewed the source to ensure that the link is actually being built properly? Quote Link to comment Share on other sites More sharing options...
mo Posted April 16, 2009 Author Share Posted April 16, 2009 Do you have a live version and/or have you viewed the source to ensure that the link is actually being built properly? yes. The rendered version is below. <html> <td class="dataListItem"> <input type="image" class="image" src="https://mysite.com/img/icons/delete.gif" alt="Delete" name="btnDelete" id="btnDelete" value="Delete" onClick="window.location.href='/cart.php?action=remove_item&smid=43&itemOption=1,5,'"> </td> </html> Quote Link to comment Share on other sites More sharing options...
mo Posted April 16, 2009 Author Share Posted April 16, 2009 What's weird is if I change my check to add isset() to the delete button. The delete works but only if I click the button than refresh the page again. I have to make the page reload twice. Also, I still cannot echo the GET variables. if($_GET["action"] == "remove_item" || isset($_POST['btnDelete'])) { if($_GET["smid"] != ""){ RemoveItem($_GET["smid"],$_GET['itemOption']); } } Quote Link to comment Share on other sites More sharing options...
mo Posted April 16, 2009 Author Share Posted April 16, 2009 After testing, the real issue is that the form needs to be reloaded when deleting the lowest level item in the cart. Meaning if I have 3 items in my cart. I can delete item 1 and 2 with no problem. However when I try to delete item 3, I need to refresh the page again before item 3 is removed. Quote Link to comment 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.