'and' or 'or' operative PHP
Hi,
I was see perform an action if the querystring 'sd' and 'ed' in the URL is not blank.
For checking one of them is blank I use
IF (empty($_GET['ed'])) {
However, i'm not sure how to proceed as i've tried AND and OR with errors.
Basically I want to perform some code only when a value is given for both 'sd' and 'ed' is given, otherwise if either are missing do nothing.
Any pointers please guys..
Re: 'and' or 'or' operative PHP
First check whether they are set using isset(). If so, check whether they contain the data in the specific format. Say if you were expecting numbers, then check whether they are numeric. If that's also true, then do whatever operation you want to perform.
If you want to continue only when both the statements are true, then use AND. Otherwise, use OR.
For example:
PHP Code:
if(isset($_GET['a']) && isset($_GET['b']))
{
echo 'Both variables are set';
}
:wave:
Re: 'and' or 'or' operative PHP
Thank you -- that works a treat.
So if && is used for 'AND', what symbol is used to represent 'OR'?
Re: 'and' or 'or' operative PHP
Re: 'and' or 'or' operative PHP
Is there something wrong with this?
Code:
if (empty($userid)) || (empty($usermode)) {
echo 'Data missing';
}
As I get the error:
Parse error: syntax error, unexpected T_BOOLEAN_OR
Re: 'and' or 'or' operative PHP
Code:
if (empty($userid) || empty($usermode)) {
:wave:
Re: 'and' or 'or' operative PHP
Quote:
Originally Posted by
akhileshbc
For example:
PHP Code:
if(isset($_GET['a']) && isset($_GET['b']))
{
echo 'Both variables are set';
}
or
PHP Code:
isset($_GET['a'], $_GET['b'])
Re: 'and' or 'or' operative PHP
Quote:
Originally Posted by
penagate
or
PHP Code:
isset($_GET['a'], $_GET['b'])
:thumb: