PHP not parsing forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wisptech@gmail.com

    PHP not parsing forms

    Here is the code that I used to test my server, very simple, right?
    But when I click on submit, nothing.. I've also tried similar things
    with php and mysql and all it did was create empty fields in the table.
    What am I doing wrong? Please help, Ultimatly I want to parse a form
    into a mysql database, but if I can't get the php engine to pass data
    from the forms correctly then it's no use to go any further.

    <?php

    if ($submit == "click"){
    echo "Hello, $UserName";
    }
    else{
    echo '
    <html><body>

    <form method="post" action="form.ph p">

    Enter Your Name
    <input type="text" name="UserName" ></input><br>

    <input type="submit" name="submit" value="click"></input>

    </form>

    </body></html>
    ';
    }

    ?>

  • Philip Ronan

    #2
    Re: PHP not parsing forms

    wisptech@gmail. com wrote:
    [color=blue]
    > Here is the code that I used to test my server, very simple, right?
    > But when I click on submit, nothing..[/color]

    Your code doesn't work because register globals have been disabled. This is
    easily fixed by retrieving the post data explicitly.

    Add this to the top of your PHP code:

    $submit = $_POST['submit'];

    More info here: <http://uk.php.net/register_global s>

    --
    phil [dot] ronan @ virgin [dot] net



    Comment

    • Daniel Tryba

      #3
      [FAQ] PHP not parsing forms (was: PHP not parsing forms)

      wisptech@gmail. com wrote:[color=blue]
      > Here is the code that I used to test my server, very simple, right?
      > But when I click on submit, nothing..
      >
      > <html><body>
      > <form method="post" action="form.ph p">
      > Enter Your Name
      > <input type="text" name="UserName" ></input><br>
      > <input type="submit" name="submit" value="click"></input>
      > </form>
      >
      > <?php
      > if ($submit == "click"){
      > echo "Hello, $UserName";
      > }
      > ?>
      > </body></html>[/color]

      Since 4.2.0 register_global s [1] is off by default due to security
      reasons [2]. One should use super globals (introduced in 4.1.0) instead
      to get to user supplied data [3]. So either fix:

      -fix your code [4]:
      if(isset($_POST['submit']) && $_POST['submit']=="click")
      {
      echo 'Hello, '.$_POST['UserName'];
      }
      -quick&dirty hack:
      extract($_REQUE ST);
      in the global scope.
      -enable register_global s

      1: http://www.php.net/manual/en/ini.cor...gister-globals
      2: http://www.php.net/manual/en/security.globals.php
      3: http://www.php.net/manual/en/languag...s.superglobals
      4: $_POST['UserName'] should offcourse be escaped properly (with
      htmlspecialchar s in this particular case).

      Comment

      • NC

        #4
        Re: PHP not parsing forms

        wispt...@gmail. com wrote:[color=blue]
        >
        > Here is the code that I used to test my server, very simple, right?
        > But when I click on submit, nothing..[/color]
        ....[color=blue]
        > if ($submit == "click"){
        > echo "Hello, $UserName";
        > }
        > else{
        > echo '
        > <html><body>
        > <form method="post" action="form.ph p">
        > Enter Your Name
        > <input type="text" name="UserName" ></input><br>
        > <input type="submit" name="submit" value="click"></input>
        > </form>
        > </body></html>
        > ';
        > }[/color]

        You probably have register_global s turned off (and you should).
        Put this in the beginning of your script:

        $UserName = $_POST['UserName'];
        $click = $_POST['click'];

        Cheers,
        NC

        Comment

        Working...