0

New PHP programmer here. Need some syntax help.

Like I know what im trying to do, here, check if that session variable is set and if its a certain string value, but the "(" you need for isset is messing the syntax up. I can't find the help im looking for via google for what is really a very simple syntax question, so I had to come here.

if (isset($_SESSION['IsValid'] AND $_SESSION['IsValid']=="Yes")) {


}else{


}
Colby Bradbury
  • 77
  • 1
  • 1
  • 9
  • `if(isset($_SESSION['IsValid']) && ($_SESSION['IsValid']=="Yes"))` --- `&&` has precedence over `AND` ;-) – Funk Forty Niner Jun 03 '14 at 19:31
  • 1
    possible duplicate of [How do check if a PHP session is empty?](http://stackoverflow.com/questions/1519818/how-do-check-if-a-php-session-is-empty) – KevinDTimm Jun 03 '14 at 19:31

2 Answers2

1
if( isset($_SESSION['IsValid']) && $_SESSION['IsValid'] == "Yes" ) {
sbeliv01
  • 11,550
  • 2
  • 23
  • 24
1

Typos:

if (isset($_SESSION['IsValid']) AND $_SESSION['IsValid']=="Yes") {
                              ^---missing                      ^---only one ) here

isset() is a function and checks a SINGLE variable if it "exists". You're trying to isset() the result of your AND operation, which is illegal syntax.

Marc B
  • 356,200
  • 43
  • 426
  • 500