Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Submission logic

Featured Replies

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

your session arrays have different keys, one is called cart-items and the other is just called items

  • 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

  • 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 by a.g.r.c

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.