Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.