Freedom-n-Democrazy Posted October 5, 2011 Author Share Posted October 5, 2011 in regards to your code are you referring to the echoing of the elements displaying with a , (comma)? When the session is empty, I get this (which is working): http://i55.tinypic.com/2mwcifm.png .. but when I add a product using that hyperlink, I get this: http://i52.tinypic.com/2r26sut.png Quote Link to comment https://forums.phpfreaks.com/topic/248463-strange-outcoming-using-action-in-a-hyperlink/page/2/#findComment-1276033 Share on other sites More sharing options...
Buddski Posted October 5, 2011 Share Posted October 5, 2011 Ok, can you put echo '<pre>' , print_r($_SESSION,true) , '</pre>'; at the end of your script. This will give us a full view of what is stored in your session. Quote Link to comment https://forums.phpfreaks.com/topic/248463-strange-outcoming-using-action-in-a-hyperlink/page/2/#findComment-1276036 Share on other sites More sharing options...
Buddski Posted October 5, 2011 Share Posted October 5, 2011 Actually, ignore that. First, the size key in your session has a typo, it says 'side' Also the variables for your ID and SIZE are not being set, these will need to be set, pretty much the same way you did in your original code. Code (now the the added feature of comments) <?php session_start(); // I have also added in a check for the ID, no point adding something if you dont have a product associated to it // if (isset($_GET['action']) && isset($_GET['size']) && isset($_GET['id']) && $_GET ['action'] == 'add') { $size = $_GET['size']; // Get the size from the URL $id = intval($_GET['id']); // Get the ID // Add it to the cart $_SESSION['cart']['content'][] = array('size' => $size, 'id' => $id); } // check if the cart is empty if (empty($_SESSION['cart']['content'])) { echo "No product in cart."; } else { // output a little message telling them how many products they have echo "You have " , count($_SESSION['cart']['content']) , " products in your cart<br/>"; // loop through the products and display them foreach ($_SESSION['cart']['content'] as $content) { echo "{$content['id']}, {$content['size']}"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/248463-strange-outcoming-using-action-in-a-hyperlink/page/2/#findComment-1276041 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 5, 2011 Author Share Posted October 5, 2011 Ahh shit so I did make a typo! Fantastic it worked! Thanks heaps for that. I've been on the computer for 14 hours straight and haven't showered for frick 27 hours. I think its time to go and have one an jump on my BMX and ride and just forget about silicin chips and remember who I am. I'm going to read over everything that has been discussed in this thread in full tomorrow when I am in a normal state of mind. Now I'm not all with it. Thanks again. It really meant allot to me. (Y)(Y) Quote Link to comment https://forums.phpfreaks.com/topic/248463-strange-outcoming-using-action-in-a-hyperlink/page/2/#findComment-1276045 Share on other sites More sharing options...
Zane Posted October 7, 2011 Share Posted October 7, 2011 Dumbest apology ever. Ahh shit so I did make a typo! Fantastic it worked! Thanks heaps for that. I've been on the computer for 14 hours straight and haven't showered for frick 27 hours. I think its time to go and have one an jump on my BMX and ride and just forget about silicin chips and remember who I am. I'm going to read over everything that has been discussed in this thread in full tomorrow when I am in a normal state of mind. Now I'm not all with it. Thanks again. It really meant allot to me. (Y)(Y) Quote Link to comment https://forums.phpfreaks.com/topic/248463-strange-outcoming-using-action-in-a-hyperlink/page/2/#findComment-1276639 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.