Results 1 to 3 of 3

Thread: why my PHP code not work?

  1. #1

    Thread Starter
    Addicted Member thirith's Avatar
    Join Date
    Oct 2004
    Posts
    196

    Resolved why my PHP code not work?

    hi all!

    i just start to learn PHP.
    and i try to get the text from text box by using the code as following:
    but it is not work.
    PHP Code:
    <body>
    <form  name=login  method="post" action="test1.php">
        Account <input name=username >
        <input type="submit" value="Singed In"  id=submit1 name=submit1>
    </form>

    </body>
    </html>
    <?
    echo "$username";
    ?>
    please help me.

    best regards,
    Thirith.
    Last edited by thirith; Jun 30th, 2005 at 03:15 AM.

  2. #2
    Member
    Join Date
    Mar 2005
    Posts
    56

    Re: why my PHP code not work?

    Use $_POST and $_GET to access your form fields:
    PHP Code:
    <body>
    <form  name=login  method="post" action="test1.php">
        Account <input name=username >
        <input type="submit" value="Singed In"  id=submit1 name=submit1>
    </form>

    </body>
    </html>
    <?
    echo $_POST['username'];
    ?>

  3. #3
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: why my PHP code not work?

    the original code will only work if register global variables is turned on and now its turned off be default.
    That will also only work is test1.php is the name of the current page.

    PHP Code:
    <body>
    <form name="login" method="post" action="<?php echo($_SERVER['PHP_SELF']); ?>">
        Account <input name="username" id="username" />
        <input type="submit" value="Singed In"  id="submit1" name="submit1" />
    </form>
    </body>
    </html>
    <?php
    echo $_POST['username'];
    ?>
    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

Posting Permissions

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



Click Here to Expand Forum to Full Width