DreamOn Posted March 12, 2011 Share Posted March 12, 2011 Hi All I have my shopping cart working correctly, just a small tweak which i would like to make to it. Here is the code i currently use... echo '<p>' . $fldname . ' <a href="cart.php?action=add&id=' . $row['idinfo'] . '">Add to report</a></p>'; But i want it so that when i click 'Add to report' is does not take me to cart.php, but it still adds the item into the shopping cart. kind of just refeshs the current page? Im sure it is only a small tweak which needs to be done.. Any help would be great -Dream Quote Link to comment Share on other sites More sharing options...
Scotty2024 Posted March 12, 2011 Share Posted March 12, 2011 Move the add function from the cart.php file to the product file or wherever the Add to report link is. Then on click execute the function when the page reloads. You could also do it with AJAX without a page refresh. Switching to ajax would be more than a small tweak though. Quote Link to comment Share on other sites More sharing options...
DreamOn Posted March 12, 2011 Author Share Posted March 12, 2011 Thanks for the reply Scotty. You need to bare with me with this as i am fairly new to PHP, about 1-2month. this is the code which was in cart.php $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; } i have added this to the top of index.php and changed the link to the following: echo '<p>' . $fldname . ' <a href="' . $_SERVER['PHP_SELF'] . '?viewdetail=' . $nameid . '&action=add&id=' . $row['idinfo'] . '">Add to report</a></p>'; but still cant get this to work, can you see where im going wrong? -Dream. Quote Link to comment Share on other sites More sharing options...
Scotty2024 Posted March 13, 2011 Share Posted March 13, 2011 Try something like this: <html> <head> <title></title> </head> <body> <?PHP session_start(); $cart = $_SESSION['cart']; $action = $_GET['action']; //test $action echo 'Value of action: ' . $action; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; } ?> <p><?=$fldname;?> <a href="<?=$_SERVER['PHP_SELF'];?>??viewdetail=<?=$nameid;?>&action=add&id=<?=$row['idinfo'];?>">Add to report</a></p> </body> </html> 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.