Results 1 to 2 of 2

Thread: Need Help with VERY Simple Forms and $_GET and $_REQUEST variables

  1. #1
    Join Date
    Jul 2007
    Location
    England
    Posts
    41
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Exclamation Need Help with VERY Simple Forms and $_GET and $_REQUEST variables

    Yep, it's me again.

    I've just started learning PHP, and I've already come across something that I can't make work...it should be pretty simple, or at least that's what this tutorial makes out!

    ---

    I am trying to create a simple 2-field form where you input your name and age. You click submit and on the next screen is displayed;

    "Welcome (*name inputed*).
    You are (*age inputed*) years old!"
    ---

    I have been given the following code add to a page;

    <form action="welcome.php" method="get">
    Name: <input type="text" name="name" />
    Age: <input type="text" name="age" />
    <input type="submit" />
    </form>
    Then, I'm told, when the user clicks the "Submit" button, the URL sent could look something like this;

    The "welcome.php" file can now use the $_GET variable to catch the form data;
    Welcome <?php echo $_GET["name"]; ?>.<br />
    You are <?php echo $_GET["age"]; ?> years old!
    ---

    I have tried renaming the page with .HTML and .PHP extensions, and adding <?php ... ?> around the whole page, and just the code...and so on. The best I have managed to achieve so far is have the form working fine, and be redirected to the correct URL like the one shown above, but alas, all that shows is the empty "Welcome", etc. template with the actual name and age missing!

    Please, try to sort me out- I suspect it's just me being dim. Oh, and when you reply, talk to me as if I'm a 5-year-old .

    MrRSMan.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    All of the code looks correct to me, so you must be placing it incorrectly.

    Using GET is acceptable, but doesn't seem needed, since you don't want this in the address bar. Using $_POST[] and method="post" will hide the data when sent, rather than placing it in the address bar. This isn't why it isn't working, but just a suggestion.

    I would suggest manually typing the URL to see if that works (for this, you would need to leave it as GET, for the time being, since you can't directly enter POST data). If so, it's the second page. If not, it's the first.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •