Neil_Bradley
asked on
if or php
I am trying to say
if is not set $_SESSION['M_valid_user'] or is not set $_SESSION['O_valid_user']
{ do this
I have this but it does not catch the "or" part of the code.
if (!isset($_SESSION['M_valid _user']) || !isset($_SESSION['O_valid_ user'] )) {
Cheers,
N
if is not set $_SESSION['M_valid_user'] or is not set $_SESSION['O_valid_user']
{ do this
I have this but it does not catch the "or" part of the code.
if (!isset($_SESSION['M_valid
Cheers,
N
ASKER
It cant be as the "do this" occurs when
$_SESSION['M_valid_user'] is not set but not $_SESSION['O_valid_user'].
I even tried switching it around and which ever Session I mention first triggers the "do this" but not the second..
N
$_SESSION['M_valid_user'] is not set but not $_SESSION['O_valid_user'].
I even tried switching it around and which ever Session I mention first triggers the "do this" but not the second..
N
Output your variables before to see:
echo $_SESSION['M_valid_user'];
echo $_SESSION['O_valid_user'];
if (!isset($_SESSION['M_valid _user']) || !isset($_SESSION['O_valid_ user'] )) {
// something
}
echo $_SESSION['M_valid_user'];
echo $_SESSION['O_valid_user'];
if (!isset($_SESSION['M_valid
// something
}
Hmm There may be another one problem that is you may not have started your session here I have a small piece of code for you check this one may help you
session_start();
$_SESSION['M_valid_user']="jagadish";
$_SESSION['O_valid_user']="someone";
if (!isset($_SESSION['M_valid_user']) || !isset($_SESSION['O_valid_user'] )){
echo "Session not set";
}else{
echo $_SESSION['M_valid_user']."<br/>";
echo $_SESSION['O_valid_user']."<br/>";
}
A small note though,
it will check the or condition i.e. it will process !isset($_SESSION['O_valid_ user']) only if !isset($_SESSION['M_valid_ user']) is false.
Can you plz paste the output of
var_dump(!isset($_SESSION[ 'M_valid_u ser']));
var_dump(!isset($_SESSION[ 'O_valid_u ser']));
it will check the or condition i.e. it will process !isset($_SESSION['O_valid_
Can you plz paste the output of
var_dump(!isset($_SESSION[
var_dump(!isset($_SESSION[
Probably $_SESSION is always 'set', so i think You coud use:
if( $_SESSION['M_valid_user'] == '' || $_SESSION['O_valid_user'] == '' )
{
//do
}
if( $_SESSION['M_valid_user'] == '' || $_SESSION['O_valid_user'] == '' )
{
//do
}
ASKER
This one has me stumped.. Everything is in place and working (session is set and variables working etc). However whichever session variable I choose to use first works and the second is ignored.
I will re write the script to achieve my goals an alternate way..
N
I will re write the script to achieve my goals an alternate way..
N
ASKER
This worked although the solution is not as efficient as if the "or" had worked.
if (isset($_SESSION['M_valid_user'])){
echo
' black space'; } else
if (isset($_SESSION['O_valid_user'])){
echo
' bank space'; } else{
echo
' my content';
}
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Change this
if (!isset($_SESSION['M_valid _user']) || !isset($_SESSION['O_valid_ user'] )) {
to
if (!isset($_SESSION['M_valid _user']) || isset(!$_SESSION['O_valid_ user'] )) {
if (!isset($_SESSION['M_valid
to
if (!isset($_SESSION['M_valid
ASKER
A difficult challenge as the answer I came up with in the end differed quite a lot from the answer I originally intended to acquire via this question. I am awarding aboo_s the points as his last post was thorough and the de bugging tips that aboo_s suggested eventually helped me find a better solution.
Cheers
N
Cheers
N
the syntax is correct, as for it not catching the or part ..well you will have to debug your program
for bugs, the problem is not here!