/    Sign up×
Community /Pin to ProfileBookmark

Are These Php issets Correct Or Not ?

Folks,

I just want to check if the ‘session type’ is ‘registration’ or not.
Q1.
Is this correct or not ?

[code]
if(!isset($_SESSION[‘session_type’] == ‘registration’))
[/code]

Or is this correct ?

[code]
if(!isset($_SESSION[‘session_type’]) == ‘registration’)
[/code]

Or, maybe none of them are correct ? How would you write it ?

Q2.
I just want to check if the ‘session type’ is ‘set’ or ‘not’ and if it is then whether the session type is ‘registration’ or not. That is all. How to check this ?
Which one of these following are correct ?

Is this one is correct ?

[code]
if(!isset($_SESSION[‘session_type’]) && if(!isset($_SESSION[‘session_type’]) == ‘registration’))
[/code]

Or is this one correct instead ?

[code]
if(!isset($_SESSION[‘session_type’]) && ($_SESSION[‘session_type’]) != ‘registration’)
[/code]

Or, maybe none of them are correct ? How would you write it ?

to post a comment

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 25.2020 — If you want to see if registration is set:
<i>
</i>if(isset($_SESSION['session_type']) and $_SESSION['session_type'] == 'registration') {

If you want to see if it is _not_ set:
<i>
</i>if(!isset($_SESSION['session_type'] or $_SESSION['session_type'] != 'registration') {
Copy linkTweet thisAlerts:
@developer_webauthorJan 29.2020 — @NogDog#1613653

I am getting this error:

Parse error: syntax error, unexpected '{' in C:xampphtdocstestindex.php on line 245.

Line 245 is the bracket "{":
<i>
</i>if(!isset($_SESSION['session_type'] or $_SESSION['session_type'] != 'registration')//Nog Dog's line
{ //This is the line where the error occurs. Line 245.


Context:
<i>
</i>function registration()
{
if(!isset($_SESSION['session_type'] or $_SESSION['session_type'] != 'registration')//Nog Dog's line
{
//Close Statement.
mysqli_stmt_close($stmt);
//Close Connection.
mysqli_close($conn);

<i> </i> die("Could not check email! Please try again later!");
<i> </i>}
<i> </i>
<i> </i>$sql_query = "INSERT INTO users (email) VALUES (?)";
<i> </i>
<i> </i>if(!$stmt = mysqli_prepare($conn,$sql_query))
<i> </i>{
<i> </i> //Close Statement.
<i> </i> mysqli_stmt_close($stmt);
<i> </i> //Close Connection.
<i> </i> mysqli_close($conn);
<i> </i>
<i> </i> die("Could register! Please try again later!");
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> //Bind Variables to the Prepared Statement as parameters.
<i> </i> mysqli_stmt_bind_param($stmt,'s',$email);
<i> </i>
<i> </i> //Attempt to execute the Prepared Statement.
<i> </i> if(!mysqli_stmt_execute($stmt))
<i> </i> {
<i> </i> //Close Statement.
<i> </i> mysqli_stmt_close($stmt);
<i> </i> //Close Connection.
<i> </i> mysqli_close($conn);
<i> </i>
<i> </i> die("Could register! Please try again later!");
<i> </i> }
<i> </i> mail();
<i> </i>}
}



NogDog, did you forget any closing circle bracket ?
Copy linkTweet thisAlerts:
@NogDogJan 29.2020 — Need a closing ) after the isset():
<i>
</i>if(!isset($_SESSION['session_type']) or $_SESSION['session_type'] != 'registration')

(The line that PHP cites as where it breaks is the line where it realizes something is wrong, not necessarily where the programmer actually made the mistake. :) )
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...