Hi i got this statement for a query to post the specific data after checking for the right "postnummer".
if($_POST['postnummer'] == "7900" or "7950" or "7960") {
$region = "Nordjylland";
}
elseif ($_POST['postnummer'] == "8654" or "8660" or "8680" or "8700") {
$region = "Midtjylland";
}
but the value posted is "Nordjylland" every time ?
You have to write
if($_POST['postnummer'] == "7900" || $_POST['postnummer'] == "7950" || $_POST['postnummer'] == "7960") {
$region = "Nordjylland";
}
elseif ($_POST['postnummer'] == "8654" || $_POST['postnummer'] == "8660" || $_POST['postnummer'] == "8680" || $_POST['postnummer'] == "8700") {
$region = "Midtjylland";
}
You can also use the switch statement, which is than easier to read:
switch ($_POST['postnummer']) {
case "7900":
case "7950":
case "7960":
$region = "Nordjylland";
break;
case "8654":
case "8660":
case "8680":
case "8700":
$region = "Midtjylland";
break;
default:
$region = "no match";
}
I think you should use arrays
$nordjyllandRegions = array("7900","7950","7960");
$midtjyllandRegions = array("8654","8660","8680","8700");
$zipcode = $_POST['postnummer'];
if(in_array($zipcode, $nordjyllandRegions)) {
$region = "Nordjylland";
}
elseif (in_array($zipcode, $midtjyllandRegions)) {
$region = "Midtjylland";
}
$postNummer = (int) $_POST['postnummer'];
if( in_array( $postNummer, array( 7900, 7950, 7960 ) ) )
{
$region = "Nordjylland";
}
elseif( in_array( $postNummer, array( 8654, 8660, 8680, 8700 ) ) )
{
$region = "Midtjylland";
}
or
$postNummer = (int) $_POST['postnummer'];
switch( $postNummer )
{
case 7900:
case 7950:
case 7960:
$region = "Nordjylland";
break;
case 8654:
case 8660:
case 8680:
case 8700:
$region = "Midtjylland";
break;
}