I’m having trouble with matching some form input to a value in an array.
Here’s my code:
if(isset($_POST['city'])){
$city = mysql_real_escape_string($_POST['city']);
$cities = array('Alamance','Archdale','Arlington');
$count = count($cities);
for($x=1; $x<=$count; $x++){
if($city === $cities[$x]){ # match }
else{ # no match, set error }
}
} else{ # city is not set, set error }
if(isset($_POST['county'])){
# county is set. make sure that it is actually a triad county
$county = mysql_real_escape_string($_POST['county']);
$counties = array('Alamance','Davidson','Davie');
foreach($counties AS $x){
if($county != $x){ # no match, set error }
else{ # match }
}
} else { # county is not set, set error }
All I want to do is match the input city or county to one in the respective array, or set an error if it doesn’t match. I’ve done this plenty of times before, so I can’t understand why it isn’t working here, but I figure maybe I’m just looking at it all too hard and need an extra pair of eyes.
Can someone please check this code and see where I’m going wrong?
This line is wrong:
it should be:
and I also suggest to change this:
into this: