July 5, 201115 yr Hey, I'm setting session data via a $_GET submission that takes an id and assigns a session variable then displays a success or fail message (this item already in cart) after. This works fine however each item can only be stored once. So when the code detects a duplicate it displays a message saying (item in cart as mentioned above). Here's my code. if(!in_array($_GET['id'], $_SESSION['cart-items'])) { $_SESSION['items'][] = $_GET['id']; $flash['cart'] = '<p><strong>'.$px_name.'</strong> has now been added to your enquiry basket.</p>'; } if(in_array($_GET['id'], $_SESSION['cart-items'])) { $flash['cart'] = '<p><strong>'.$px_name.'</strong> is already in your cart.</p>'; } Both parts fire now upon setting the session and the later being the one that is outputted. What's a suitable way to overcome this issue? Any help appreciated. Thanks
July 5, 201115 yr your session arrays have different keys, one is called cart-items and the other is just called items
July 5, 201115 yr Author your session arrays have different keys, one is called cart-items and the other is just called items Ah sorry I was editing slightly before posting here. There is no such fault in the live code. Same question still applies, any ideas? Ty dude
July 12, 201115 yr Author Just as an fyi for anyone running into this problem in the future the trick is to switch the logic the other way around. The logic is fine, but being executed in a procedural fashion both items get hit. So check the not condition last. Thread can be closed. Edited July 12, 201115 yr by a.g.r.c
Create an account or sign in to comment