0

I'm trying to get the user to enter their name into a text box, and then output it through each page (part of switch and case):

default:
   $message = "Enter your name and click start.";
   $nextDecision = "
                <form action=\"index.php\" method=\"POST\">
                <input type=\"text\" name=\"input_value\">
                <input type=\"submit\" value=\"Start\" name=\"submit\" />
                </form>";


                if (isset($_POST['submit']))
                {
                // Execute this code if the submit button is pressed.
                $name = $_POST['input_value'];


                $message = "message";
                $nextDecision = "<form action=\"index.php\" method=\"get\">
                <input type=\"radio\" name=\"choice\" value=\"back\">choice<br>
                <input type=\"submit\">
                </form>";

                }
    break;

In my index.php page, it will print the name until the user presses submit and goes to a different case, outside of the if statement. Is there a way to pass the variable outside of the if statement?

Jordan
  • 21
  • 1
  • 2
  • 8
  • You have to save that value in session variable or cookie. – Elon Than Oct 14 '13 at 01:04
  • define the variable `$name` outside the `if` and assign the variable inside `if` so that the variable `$name` becomes globally available throughout the page – Deepak Oct 14 '13 at 01:04
  • @ElonThan how do I write `$name` to a cookie or session if I have to define name as `$name = $_POST['input_value'];` – Jordan Oct 14 '13 at 02:35
  • After defining you can do what you want with variables, so you can save it in cookie or session without any problems. – Elon Than Oct 14 '13 at 02:39
  • have you read the manual, it's fairly detailed. [cookies](http://php.net/manual/en/features.cookies.php) and [sessions](http://www.php.net/manual/en/book.session.php). – gwillie Oct 14 '13 at 04:53

0 Answers0