Note that there are some explanatory texts on larger screens.

plurals
  1. POphp switch statement using text box/drop down box
    text
    copied!<p>I am trying to use a switch statement to make it so that when that specific word is typed into the text box it will display the available models of that car </p> <p>for example</p> <p>if the user entered "Volkswagen" it should echo "The available models are Beetle and Polo"</p> <p>But for some reason it isnt working can anyone suggest to me why?</p> <p>here is the code i have so far, </p> <pre><code>&lt;form action="switch.php" method="post"&gt; &lt;input type="text" name="cars" id="cars" /&gt; &lt;input type="submit" /&gt; &lt;?php $i = $_POST; ?&gt; &lt;?php switch ($i) { case "Volkswagen": echo "The available models are Beetle and Polo"; break; case "Renault": echo "The Available models are Megane and Clio"; break; case "Land Rover": echo "The Available models are Range Rover Sport and Defender"; break; } ?&gt; &lt;/form&gt; </code></pre> <p>EDIT: </p> <p>I am a bit stuck now i am trying to use this switch statement with a drop down box and not quite sure how i can make them work together if anyone can help me to make them work together that would be great</p> <p>this is the code I have for the working switch and a working drop box.</p> <pre><code>&lt;form action=""&gt; &lt;select name="cars"&gt; &lt;option value="Volkswagen"&gt;Volkswagen&lt;/option&gt; &lt;option value="Renault"&gt;Renault&lt;/option&gt; &lt;option value="Land Rover"&gt;Land Rover&lt;/option&gt; &lt;/select&gt; &lt;p&gt; &lt;?php switch($_POST['cars']) { case "Volkswagen": echo "The available models are Beetle and Polo"; break; case "Renault": echo "The Available models are Megane and Clio"; break; case "Land Rover": echo "The Available models are Range Rover Sport and Defender"; break; } ?&gt; &lt;/p&gt; &lt;/form&gt; &lt;/center&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload