need quick help with if statement

Discussion in 'PHP' started by surfnearnzone, Mar 25, 2011.

  1. #1
    Can you point out what is wrong with this code:

    if($email=="")
    {
    $link=="site1.com" ;
    }
    else
    {
    $link="site2.com";
    }

    $email value is taken from $_POST and passed onto <a href="<php $link>/click.php>

    I get site2.com when $email is not null but I don't get site1.com when $email is null.

    Please help:confused:
     
    surfnearnzone, Mar 25, 2011 IP
  2. sojic

    sojic Active Member

    Messages:
    133
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    90
    #2
    Try with
    
    if ($_POST['email']=='')
    
    Code (markup):
     
    sojic, Mar 25, 2011 IP
    surfnearnzone likes this.
  3. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #3
    You've got an extra equals sign in this line:

    $link=="site1.com" ;


    Should be:

    $link=="site1.com" ;
     
    plog, Mar 25, 2011 IP
    surfnearnzone likes this.
  4. surfnearnzone

    surfnearnzone Well-Known Member

    Messages:
    1,492
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    165
    #4
    Both the solutions worked for me. thanks, rep added :)

    Although, you too wrote the code wrong but I got it what you are saying.
     
    surfnearnzone, Mar 25, 2011 IP
  5. Kload

    Kload Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You can also redirect it through the php code like header("Location: http://site.com");
     
    Kload, Mar 27, 2011 IP