Reputation: 27
I have an unexpected ; error on this line:
$action = ($sessionMinus == $_SESSION['initial_count']) ? 'create_session2.php';
But if I remove the ; then it states unexpected { in the line below, how can this be sorted out?
below full code:
if ($sessionMinus == $_SESSION['initial_count']){
$action = ($sessionMinus == $_SESSION['initial_count']) ? 'create_session2.php';
}else if($sessionMinus != $_SESSION['initial_count']){
$action = ($sessionMinus != $_SESSION['initial_count']) ? $_SERVER['PHP_SELF'];
}
Upvotes: 0
Views: 74
Reputation: 33383
To use the ternary operator, you need to have values for when the condition is both TRUE and FALSE:
$action = ($sessionMinus != $_SESSION['initial_count']) ? $_SERVER['PHP_SELF'] : "false";
I am not sure why you are doing the checks twice, the following should suffice:
<?php
if ($sessionMinus == $_SESSION['initial_count']){
$action = 'create_session2.php';
}else($sessionMinus != $_SESSION['initial_count']){
$action = $_SERVER['PHP_SELF'];
}
Upvotes: 1
Reputation: 76240
All of you code can be rewritten as:
$action = ($sessionMinus == $_SESSION['initial_count']) ? 'create_session2.php' : $_SERVER['PHP_SELF'];
Have fun.
Upvotes: 0
Reputation: 1507
You might forgot else command
$action = ($sessionMinus == $_SESSION['initial_count']) ? 'create_session2.php':'';
Upvotes: 0
Reputation: 19979
A ternary operation requires that you add an alternative if the condition is not true (instead it is false):
$action = ($sessionMinus == $_SESSION['initial_count']) ? 'create_session2.php' : 'was_false';
Psuedo looks like:
$variable = ($condition == true) ? true : false;
You can read more about comparison operators (and ternary) here.
Upvotes: 0
Reputation: 57709
You have a short if statement: [condition] ? [if_true] : [if_false]
but the : [if_false]
part is missing
Upvotes: 1