SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: Problem with simple if statement
-
Jan 4, 2005, 10:27 #1
- 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";
}
-
Jan 4, 2005, 10:30 #2
- 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
-
Jan 4, 2005, 10:31 #3
- 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
-
Jan 4, 2005, 10:31 #4
- 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
-
Jan 4, 2005, 10:32 #5
Use == for testing, not =
Better would be
PHP Code:if ('UPS' == $carrier)
{
}
else if ('FED-EX' == $carrier)
{
}
...
PHP Code:switch ($carrier)
{
case 'UPS':
// do ups stuff
break;
case 'FED-EX':
// do FedEx stuff
break;
default:
// do default stuff
break;
}
Bookmarks