php switch statement using text box/drop down box -
i trying use switch statement make when specific word typed text box display available models of car
for example
if user entered "volkswagen" should echo "the available models beetle , polo"
but reason isnt working can suggest me why?
here code have far,
<form action="switch.php" method="post"> <input type="text" name="cars" id="cars" /> <input type="submit" /> <?php $i = $_post; ?> <?php switch ($i) { case "volkswagen": echo "the available models beetle , polo"; break; case "renault": echo "the available models megane , clio"; break; case "land rover": echo "the available models range rover sport , defender"; break; } ?> </form>
edit:
i bit stuck trying use switch statement drop down box , not quite sure how can make them work if can me make them work great
this code have working switch , working drop box.
<form action=""> <select name="cars"> <option value="volkswagen">volkswagen</option> <option value="renault">renault</option> <option value="land rover">land rover</option> </select> <p> <?php switch($_post['cars']) { case "volkswagen": echo "the available models beetle , polo"; break; case "renault": echo "the available models megane , clio"; break; case "land rover": echo "the available models range rover sport , defender"; break; } ?> </p> </form> </center>
$_post
array. not can compare against strings. php convert array literal word array
. since don't have case word, no matches @ all.
form values submitted elements of $_post array. should doing
switch($_post['cars']) { ... }
instead
Comments
Post a Comment