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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

conditional form variable

Status
Not open for further replies.

Diggum1

Programmer
Oct 14, 2004
67
US
I know this should be simple, but I just started php. I have a form that will submit an email. The company name will be set by a selection from a drop down (with values of Company1,Company2,Company3). What I have below always returns Company3, regardless of which option I select from the drop down.

Any ideas?
Thanks
RK

$name = $_POST["name"];
$title = $_POST["title"];
$phone = $_POST["phone"];
$fax = $_POST["fax"];
$email = $_POST["email"];
$company = $_POST["company"];


if($company='Company1')
$company="Company1\n10 First Ave\nChicago, IL";
if($company='Company2')
$company="Company2\n10 Second Ave\nChicago, IL";
if($company='Company3')
$company="Company3\n10 Third Ave\nChicago, IL";
 
Your Ifs aren't right. in PHP you need two or more = signs to make a comparison, one = sign is an assignment.

What you are actually doing is assigning the value of "company X" to the $company variable and then checking if it was correctly assigned. and since the assignment is always correct, it returns true. Meaning it goes through the 3 conditionals overwriting the value of the $company variable each time,


Try this instead:


Code:
if($company[red]==[/red]'Company1')
    $company="Company1\n10 First Ave\nChicago, IL";
if($company'[red]==[/red]Company2')
    $company="Company2\n10 Second Ave\nChicago, IL";
if($company[red]==[/red]'Company3')
    $company="Company3\n10 Third Ave\nChicago, IL"; [\code]

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks for the explanation, it works great.
 
No problem. Glad it worked

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top