Jump to content

[SOLVED] Multiple if()'s


tawevolution

Recommended Posts

Hi, I have this bit of code:

 

<?php
$to=$_POST['to'];

//Define Enquiry Types
if($to="general"){ $type="General"; }
if($to="pr"){ $type="Sponsership & Public Relations"; }
if($to="jobs"){ $type="Job Applications"; }
if($to="web"){ $type="Website Feedback"; }

echo($type)
?>

 

The $to is retrieved from a form on another page (which works because when i echo($to); it comes out right), but when it comes to corresponding to $to with a $type it only shows the last one.

 

e.g. $to could be "pr", so $type should be "Sponsership & Public Relations", but it allways comes up with "Website Feedback".

 

a) Why is this?

and b) how do I fix it?

 

Thanks

Evo

Link to comment
https://forums.phpfreaks.com/topic/50252-solved-multiple-ifs/
Share on other sites

because you are using a single = sign which assigns variable, they should all be == signs which means is equal to

 

$to=$_POST['to'];

//Define Enquiry Types
if($to=="general"){ $type="General"; }
if($to=="pr"){ $type="Sponsership & Public Relations"; }
if($to=="jobs"){ $type="Job Applications"; }
if($to=="web"){ $type="Website Feedback"; }

echo($type)

 

maybe better to use a switch statement

Link to comment
https://forums.phpfreaks.com/topic/50252-solved-multiple-ifs/#findComment-246660
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.