Results 1 to 8 of 8

Thread: 'and' or 'or' operative PHP

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    137

    '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..

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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,...

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    137

    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'?

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: 'and' or 'or' operative PHP

    two pipes: ||

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    137

    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

  6. #6
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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,...

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: 'and' or 'or' operative PHP

    Quote Originally Posted by akhileshbc View Post
    For example:
    PHP Code:
    if(isset($_GET['a']) && isset($_GET['b']))
    {
      echo 
    'Both variables are set';

    or
    PHP Code:
    isset($_GET['a'], $_GET['b']) 

  8. #8
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: 'and' or 'or' operative PHP

    Quote Originally Posted by penagate View Post
    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
  •  



Click Here to Expand Forum to Full Width