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
https://forums.phpfreaks.com/topic/265991-unset-function/#findComment-1363015
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
https://forums.phpfreaks.com/topic/265991-unset-function/#findComment-1363018
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.