IF elseif else usage
So, now I've been trying to learn If, elseif and else statements properly. And I'm doing something wrong. ![]()
A guy told me his website would email specific people based on what zipcode they put in the contact form on his site. I was wondering how he did it, so I tried to recreate something similar.
Here is what I've done:
1. I created a file called zipcodes.php
2. In this file it has set every zipcode to a variable. For instance:
<?php
$Nashville=("37010" or "37027" or "37040" or "37055" or "37152");
?>
3. I created a form with a field called 'zip'.
4. I created a php file called phpmail.php to send this form.
5. Right now, the top of this file looks like this:
<?php
include("zipcodes.php");
$zip=$_POST["zip"];
//NASHVILLE//
if ($zip==$Nashville)
$my_email = "email1@mysite.com";
//Knoxville//
if ($zip==$Knoxville)
$my_email = "email2@mysite.com";
//Huntsville//
if ($zip==$Huntsville)
$my_email = "email3@mysite.com";
...etc.
This doesn't work. It sends them all to the last option which is texas or email15@mysite.com
Before I had the first if set to if and all the others set to elseif
But that didn't work. It sent all the emails to Nashville email I made.
If statements must work though in this way. Because if I have this:
if ($zip==$Nashville)
$my_email = "email1@mysite.com";
//Anything Else//
else $my_email = "hippityhoppity@live.com";
It works. Meaning if a zipcode is in Nashville it goes to one email - and if it isn't in Nashville - it goes to hippityhoppity.
Am I not getting something about all of this? Thanks!
