cdoyle Posted August 22, 2008 Share Posted August 22, 2008 Hi, I've never did anything with a switch/case before, but now I'm trying to create a form where a user can select from a drop down. Then when they hit the submit button, the page will do something depending on their selection. I first created my form, and then tried creating my switch/case function but it wasn't working. So now I'm just trying to get it to say something when 'Strength' is selected, and it's still not working. So I don't think i'm referencing my form or field right. Here is what I have so far, switch($_Post['train']) { case "Strength": echo "test"; break; } include("templates/private_header.php"); echo "<h3>Welcome to the CAC World Gym!</h3><br>As a member you have access to all of our gym equipment, please make your selection below.<p>"; echo "<form method=\"post\" action=\"gym.php\">"; echo "<select name=\"train\"\n"; echo "<option value=\"Strength\">Strength</option>\n"; echo "<option value=\"Speed\">Speed</option>\n"; echo "<input type=\"submit\" value=\"train\" />\n"; echo $_POST["train"]; include("templates/private_footer.php"); am I on the right track? In this example, if 'Strength is selected it should display the word 'test' but it's not. It just refreshes the page. Link to comment https://forums.phpfreaks.com/topic/120795-solved-help-with-optionswitch-case/ Share on other sites More sharing options...
pocobueno1388 Posted August 22, 2008 Share Posted August 22, 2008 I think $_POST is case sensitive, and you have it as $_Post. Change switch($_Post['train']) To switch($_POST['train']) Link to comment https://forums.phpfreaks.com/topic/120795-solved-help-with-optionswitch-case/#findComment-622648 Share on other sites More sharing options...
cdoyle Posted August 22, 2008 Author Share Posted August 22, 2008 Ah Crap! out of all the searching I did, and all the different web sites I looked up on this. I never noticed that!!! It works now. geeze something so simple! Link to comment https://forums.phpfreaks.com/topic/120795-solved-help-with-optionswitch-case/#findComment-622650 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.