4 Replies - 436 Views - Last Post: 18 October 2019 - 04:02 AM Rate Topic: -----

#1 makamo66   User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 104
  • Joined: 04-February 09

Null session array condition not met until page is refreshed

Posted 17 October 2019 - 04:30 PM

When I use the following code, it doesn't print out "else test" until after I refresh the page.

unset($_SESSION["product"]);

if ( !empty($_SESSION["product"]) && ($_SESSION["product"] != NULL)) {
echo "if test";
} else {
echo "else test";
}
:code:/>

When I use:

var_dump($_SESSION["product"]);
:code:/>

It shows:

array(0) { }

editted this post to remove the else if condition and use else instead

This post has been edited by makamo66: 18 October 2019 - 03:06 AM
Reason for edit:: In the future please use the [code] tag button in the editor


Is This A Good Question/Topic? 0
  • +

Replies To: Null session array condition not met until page is refreshed

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15497
  • View blog
  • Posts: 62,060
  • Joined: 12-June 08

Re: Null session array condition not met until page is refreshed

Posted 17 October 2019 - 04:39 PM

Why you would be using an ELSE IF with no condition? Why not just an 'else'?

5	} else if {


https://www.w3school...php_if_else.asp
Was This Post Helpful? 0
  • +
  • -

#3 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2494
  • View blog
  • Posts: 7,551
  • Joined: 15-January 14

Re: Null session array condition not met until page is refreshed

Posted 17 October 2019 - 04:56 PM

Yeah, you need to show the actual code you're using if you want an answer about the actual problem that you're having. Right now that code doesn't do anything at all because there's a syntax error in it.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4246
  • View blog
  • Posts: 13,461
  • Joined: 08-June 10

Re: Null session array condition not met until page is refreshed

Posted 18 October 2019 - 01:51 AM

Quote

!empty($_SESSION["product"]) && ($_SESSION["product"] != NULL)

You are aware that these two tests do the same?
Was This Post Helpful? 1
  • +
  • -

#5 makamo66   User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 104
  • Joined: 04-February 09

Re: Null session array condition not met until page is refreshed

Posted 18 October 2019 - 04:02 AM

The code didn't actually make the call to unset the variables until after the not empty conditional was asked. I was misled because var_dump still printed out an empty session array. Once I changed the order of my code, it worked.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1