Hello guys! I'm having a problem with a my simple form. The problem is that neither "echo $_POST['choice'];" nor the switch outputs anything. That probably means something wring with the form. This script is available for the users at index.php?d=test and I think maybe that has something to do with it in the <form> tag. In case it's worth mentioning the text "This works!" still appears everytime I submit the form. I'm not sure if I'm expressing myself well here, but please tell me if you don't understand what I mean. <?php if ( isset ( $_POST['options'] ) ) { echo "This works!"; echo $_POST['choice']; switch ( $_POST['choice'] ) { case "3": echo "Option 3 is chosen"; break; case "2": echo "Option 2 is chosen"; break; case "1": echo "Option 1 is chosen"; break; } } else { ?> <table> <tr> <td> <form action="" method="post"> <select> <option name=\"choice\" value=\"1\">-- Options --</option> <option name=\"choice\" value=\"2\">Option 2</option> <option name=\"choice\" value=\"3\">Option 3</option> </select> <input type="submit" name="options" value="Submit" /> </form> </td> </tr> </table> <?php } ?> PHP:
i suggest you to learn basic html tags <select name="choice"> <option value="1">-- Options --</option> <option value="2">Option 2</option> <option value="3">Option 3</option> HTML:
I know basic html tags. I've tried your suggested code, but that didn't work. I've changed it now so that the name-attribute is only inside the select-tag but it still doesn't work... Do you have any other suggestions?
uhm why are you escaping the values with a back-slash? tried to actually put the page name in the action attribute for the form? the code MC_delta_T gave you ought to work if there is no other problems we can't see
this solution should work =) if you want to see if all the data were passed or not, try this echo "<pre>"; print_r($_POST); echo "</pre>"; PHP: with this you can see all the contents of the POST variable.
<select name="choose"> <option value="0">Choose an option ..</option> <option value="1">First Option</option> <option value="2">Second Option</option> <option value="3">Third Option</option> </select> <?php $pselect = $_POST["choose"]; echo "You selected option Nr.", $pselect; ?> PHP:
I noticed that your HTML code has PHP like quotation marks \". You should just replace it with only quotes "choice". Now try your program as you like ....