Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    67
    Thanks
    20
    Thanked 0 Times in 0 Posts

    Question Simple Form Submission

    I'm working on a script which [is supposed to] submit a form to itself, process data, and display it.

    I've watered down the code to the form-specific elements:
    PHP Code:
    <?php
    echo'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>PHP Form Test</title>
    </head>'
    ;

        if (
    $_GET['act'] == "Submit") {
            
    $_POST["Text"];
        }

    echo
    '
    <body>
    <form action="test.php?act=Submit" method="post" name="Test">
    <input name="Text" type="text" />
    <input name="submit" type="submit" />
    </form>'
    ;

    echo 
    '<p>'; echo $Text; echo '</p>';

    echo
    '
    </body>
    </html>'
    ;
    ?>
    In theory, that script should show whatever's entered into the text field in a paragraph after submission. But it doesn't. I've been pondering over this for some time and have yet to find a viable explanation. The code that this was derived from has worked in the past, however, right now I'm only testing it on a localhost setup.

    Any input would be appreciated.
    Last edited by coolcamo8642; 08-27-2009 at 02:05 AM. Reason: Problem Resolved.

  • #2
    Regular Coder funnymoney's Avatar
    Join Date
    Aug 2007
    Posts
    364
    Thanks
    17
    Thanked 24 Times in 24 Posts
    probably here is the problem

    PHP Code:
    if ($_GET['act'] == "Submit") {
           
    $Text $_POST["Text"];
        } 

  • Users who have thanked funnymoney for this post:

    coolcamo8642 (08-27-2009)

  • #3
    New Coder
    Join Date
    Jun 2006
    Posts
    67
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Okay, wow. That was so simple even I didn't expect it, but it worked. I know that it has worked in the past as I posted it, but I suppose a newer version of PHP could have a more strict syntax.

    Thanks for your help!

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    It has to do with register_globals being turned off by default in newer versions of PHP to prevent against manipulation where a hacker could add info via say, $_GET and override a session variable which told the script whether you were logged in or not.

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION


  •  

    Posting Permissions

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