Results 1 to 8 of 8

Thread: 'and' or 'or' operative PHP

  1. #1
    Addicted Member
    Join Date
    May 06
    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 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,557

    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 Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  3. #3
    Addicted Member
    Join Date
    May 06
    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 02
    Posts
    21,655

    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 subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * 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??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

  5. #5
    Addicted Member
    Join Date
    May 06
    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 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,557

    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 Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  7. #7
    Moderator
    Join Date
    Jan 05
    Location
    Sydney
    Posts
    13,612

    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 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,557

    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 Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •