Jump to content

UNSET Function


shyam13

Recommended Posts

That's odd. Check your logic, and verify that code isn't executing on every load

 

<?php

session_start();

$_SESSION['cart'] = 'test';

echo $_SESSION['cart'];
// outputs 'test'

unset($_SESSION['cart']);

echo $_SESSION['cart'];
// undefined index notice

$_SESSION['cart'] = 'foobar';

echo $_SESSION['cart'];
// outputs foobar

?>

 

That proves even if you unset a variable, you should be able to redefine it afterwards.

 

You might have errors that aren't showing as well, you could try emptying rather than unsetting

 

if (isset($_POST['clear']))
$_SESSION['cart'] = array();

Link to comment
Share on other sites

I have just reread my code, there is nothing wrong with my logic which is quite strange, i changed the code to use :

 

<?php if (isset($_POST['clear']))

$_SESSION['cart'] = array();

  ?>

 

but I still have the same problem, no products are added to the cart.

 

Thank you

 

Shyam

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.