SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist jimday1982's Avatar
    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with simple if statement

    I'm using this if statement:

    PHP Code:
                if ($carrier "UPS") {
                 
    $emailbody .= "Tracking link: http://wwwapps.ups.com/etracking/tracking.cgi?TypeOfInquiryNumber=T&InquiryNumber1=" $number "\n\n";
                 }
                 
                 elseif (
    $carrier "FED-EX") {
                 
    $emailbody .= "Tracking link: http://www.fedex.com/cgi-bin/tracking?action=track&language=english&cntry_code=us&initial=x&mps=y&tracknumbers=" $number "\n\n";
                 }
                 
                 elseif (
    $carrier "USPS") {
                 
    $emailbody .= "Tracking link:  http://www.usps.com/shipping/trackandconfirm.htm\n\n";
                 }
                 
                 else{
                 
    $nolink "1";
                 
    $emailbody .= "\n\n";
                 }
                 
    //$emailbody .= "Order ID: " . $order_id . "\n\n";
                 
    if ($nolink "1"){
                 }
                 else{
                 
    $emailbody .= "To track your package, please click the link above.\n"
                 } 
    and all of the records in my database have nothing in the "carrier" field. I don't understand that when my code sends the emails (furhter down in the code), they all include the UPS link. I have it set in my code to only include that link if the "carrier" field contains "UPS"...am I missing something here? Thanks for your help.
    Jimmy Day
    Senior Systems Analyst
    Piedmont Healthcare Corporation

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you said
    if ($carrier = "UPS")
    but it should be
    if ($carrier == "UPS")

    two == sign everywhere even for "Fed-Ex" or something else

    == means check if they are ewual and
    = means make them equal and this always gonna be true RIGHT

  3. #3
    SitePoint Evangelist jimday1982's Avatar
    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Crap, nevermind...I needed "==" in my if statements.

    Thanks for the quick reply though.
    Last edited by jimday1982; Jan 4, 2005 at 10:32. Reason: Owned
    Jimmy Day
    Senior Systems Analyst
    Piedmont Healthcare Corporation

  4. #4
    SitePoint Guru MikeBigg's Avatar
    Join Date
    Jun 2004
    Location
    Reading, UK
    Posts
    970
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is because you need to use the double equals ( == ) for comparisons in PHP.

    In the if statement you are setting $carrier equal to 'UPS ' which then returns true and so the first clause is executed.

    Mike

  5. #5
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use == for testing, not =

    Better would be

    PHP Code:
      if ('UPS' == $carrier)
      {
      }
      else if (
    'FED-EX' == $carrier)
      {
      }
      ... 
    Better than that, IMHO

    PHP Code:
      switch ($carrier)
      {
        case 
    'UPS':
           
    // do ups stuff
            
    break;
        case 
    'FED-EX':
           
    // do FedEx stuff
            
    break;
        default:
           
    // do default stuff
            
    break;
      } 


Bookmarks

Posting Permissions

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