|
-
Jun 16th, 2012, 12:49 PM
#1
Thread Starter
Addicted Member
'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..
-
Jun 17th, 2012, 02:50 AM
#2
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';
}
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jun 17th, 2012, 08:18 AM
#3
Thread Starter
Addicted Member
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'?
-
Jun 17th, 2012, 08:20 AM
#4
Re: 'and' or 'or' operative PHP
-
Jun 17th, 2012, 09:33 AM
#5
Thread Starter
Addicted Member
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
-
Jun 17th, 2012, 10:08 AM
#6
Re: 'and' or 'or' operative PHP
Code:
if (empty($userid) || empty($usermode)) {
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jun 17th, 2012, 07:15 PM
#7
Re: 'and' or 'or' operative PHP
 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'])
-
Jun 18th, 2012, 03:45 AM
#8
Re: 'and' or 'or' operative PHP
 Originally Posted by penagate
or
PHP Code:
isset($_GET['a'], $_GET['b'])
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|