tawevolution Posted May 6, 2007 Share Posted May 6, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50252-solved-multiple-ifs/ Share on other sites More sharing options...
paul2463 Posted May 6, 2007 Share Posted May 6, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50252-solved-multiple-ifs/#findComment-246660 Share on other sites More sharing options...
tawevolution Posted May 6, 2007 Author Share Posted May 6, 2007 All done, thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/50252-solved-multiple-ifs/#findComment-246664 Share on other sites More sharing options...
MadTechie Posted May 6, 2007 Share Posted May 6, 2007 please click solved as a side note lookup switch Quote Link to comment https://forums.phpfreaks.com/topic/50252-solved-multiple-ifs/#findComment-246702 Share on other sites More sharing options...
tawevolution Posted May 6, 2007 Author Share Posted May 6, 2007 please click solved as a side note lookup switch oh yea ... forgot about that ...... and im going to look up switch now Quote Link to comment https://forums.phpfreaks.com/topic/50252-solved-multiple-ifs/#findComment-246709 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.