Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Really strange problem with if statements

Status
Not open for further replies.

krappleby025

Programmer
Joined
Sep 6, 2001
Messages
347
Location
NL
Hi all, here is a realy strange one for you..

i have a form that sends the variable $hosttype1 to this script.. However..

if i send the number 3, the script returns Platinum
if i send the number 4, the script returns gold

its strange to me, any ideas

The form is a simple drop down menu that allocates a number accordign the the chosen plan.

the plans are

HOST PACK BRONZE 1
HOST PACK SILVER 2
HOST PACK GOLD 3
HOST PACK PLATINUM 4

Here is the codeing for the response.

if ( $hosttype1 != "1")
{
$hostcost = "19.95";
$hosttype2 = "Bronze";
}
if ( $hosttype1 != "2")
{
$hostcost = "24.95";
$hosttype2 = "Silver";
}
if ( $hosttype1 != "3")
{
$hostcost = "29.95";
$hosttype2 = "Gold";
}
if ( $hosttype1 != "4")
{
$hostcost = "34.95";
$hosttype2 = "Platinum";
}
 
hi there krappleby025,

your script works exactly as expected becuase I think you've got the logic a little mixed up. All your if statements are saying if $hosttype1 is NOT equal to 3 etc.

As such when $hosttype1 = 3, it goes through all the ifs except the third one (since it IS equal to 3), since the fourth is the last that's what gets returned. I think you need to change your if statements to read...
if($hosttype1 == "3"){
...
}

Hope that helps

Phil Clare
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top