parka Posted March 8, 2007 Share Posted March 8, 2007 On a form there's a list of countries for the user to choose from. On the processing script, how can I check to make sure that users have indeed choosen from the list I have provided? I tried the following but it gave me a "parse error, unexpected T_FOREACH, expecting T_CASE or T_DEFAULT or '}'" on the line with the foreach statement. How should I code this security check? $countriesArray = array("usa", "china", "russia", "mexico"); $userChoosenCountry = "holland"; // to be replaced by $_POST later switch ($userChoosenCountry){ foreach ($countriesArray as $country){ case $country: print "You have choosen $country"; break; } default: print "You didn't choose from the list of countries"; } Link to comment https://forums.phpfreaks.com/topic/41739-using-foreach-inside-switch/ Share on other sites More sharing options...
vbnullchar Posted March 8, 2007 Share Posted March 8, 2007 $countriesArray = array("usa", "china", "russia", "mexico"); $userChoosenCountry = "holland"; // to be replaced by $_POST later if(in_array($userChoosenCountry,$countriesArray)) { echo "you choose".$userChoosenCountry; } Link to comment https://forums.phpfreaks.com/topic/41739-using-foreach-inside-switch/#findComment-202427 Share on other sites More sharing options...
parka Posted March 8, 2007 Author Share Posted March 8, 2007 Thanks! Link to comment https://forums.phpfreaks.com/topic/41739-using-foreach-inside-switch/#findComment-202456 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.