Jump to content

[SOLVED] help with option/switch case


cdoyle

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.