Beginners problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rolf Wester

    Beginners problem

    Hi,

    I'm just beginning PHP programming. I have installed Apache 2.0.48 and
    PHP 4.3.3. The installation went well. Then I was trying a little example.

    HTML page:

    <html>
    <head>
    <title>test</title>
    </head>

    <body>

    <form action="test.ph p" method=POST>
    First Name: <input type=text name=firstname size=30
    MAXLENGTH=150>
    <input type=submit value="Send">
    </form>

    </body>
    </html>

    and the PHP script "test.php":

    <?php
    echo "First Name = ";
    echo $firstname;
    echo ".";
    ?>

    When I insert "Rolf" into the textfield and hit the "Send" button I get
    the response:

    First Name = .

    Nothing else. I thought that the variable $firstname is set to the
    string I inserted into the text field. Did I do anything wrong or could
    there be a problem with apache or php? I would be very appreciative for
    help on this problem.

    Regards

    Rolf Wester

    P.S.: When using method GET the form calls:

    The Response is the same as before.


  • Kevin Thorpe

    #2
    Re: Beginners problem

    Rolf Wester wrote:
    [color=blue]
    > Hi,
    >
    > I'm just beginning PHP programming. I have installed Apache 2.0.48 and
    > PHP 4.3.3. The installation went well. Then I was trying a little example.
    >
    > HTML page:
    >
    > <html>
    > <head>
    > <title>test</title>
    > </head>
    >
    > <body>
    >
    > <form action="test.ph p" method=POST>
    > First Name: <input type=text name=firstname size=30
    > MAXLENGTH=150>
    > <input type=submit value="Send">
    > </form>
    >
    > </body>
    > </html>
    >
    > and the PHP script "test.php":
    >
    > <?php
    > echo "First Name = ";
    > echo $firstname;
    > echo ".";
    > ?>
    >
    > When I insert "Rolf" into the textfield and hit the "Send" button I get
    > the response:
    >
    > First Name = .
    >
    > Nothing else. I thought that the variable $firstname is set to the
    > string I inserted into the text field. Did I do anything wrong or could
    > there be a problem with apache or php? I would be very appreciative for
    > help on this problem.
    >
    > Regards
    >
    > Rolf Wester
    >
    > P.S.: When using method GET the form calls:
    > http://localhost:8080/test.php?firstname=Rolf
    > The Response is the same as before.
    >[/color]

    Very common problem this. You have register_global s turned off, it's the
    default in recent releases of php.

    replace
    echo $firstname;
    with
    echo $_POST['firstname'];
    and all will be well

    Comment

    • sanya@fan.astral.ntu-kpi.kiev.ua

      #3
      Re: Beginners problem

      On Fri, 31 Oct 2003 17:53:45 +0100
      Rolf Wester <wester@ilt.fra unhofer.de> wrote:
      [color=blue]
      > Hi,
      >
      > I'm just beginning PHP programming. I have installed Apache 2.0.48 and
      > PHP 4.3.3. The installation went well. Then I was trying a little example.
      >
      > HTML page:
      >
      > <html>
      > <head>
      > <title>test</title>
      > </head>
      >
      > <body>
      >
      > <form action="test.ph p" method=POST>
      > First Name: <input type=text name=firstname size=30
      > MAXLENGTH=150>
      > <input type=submit value="Send">
      > </form>
      >
      > </body>
      > </html>
      >
      > and the PHP script "test.php":
      >
      > <?php
      > echo "First Name = ";
      > echo $firstname;
      > echo ".";
      > ?>[/color]
      /////////////////////////////////////////////////////////
      in php.ini register_global s = On or use $HTTP_POST_VARS["firstname"]
      ////////////////////////////////////////////////////////
      [color=blue]
      >
      > When I insert "Rolf" into the textfield and hit the "Send" button I get
      > the response:
      >
      > First Name = .
      >
      > Nothing else. I thought that the variable $firstname is set to the
      > string I inserted into the text field. Did I do anything wrong or could
      > there be a problem with apache or php? I would be very appreciative for
      > help on this problem.
      >
      > Regards
      >
      > Rolf Wester
      >
      > P.S.: When using method GET the form calls:
      > http://localhost:8080/test.php?firstname=Rolf
      > The Response is the same as before.
      >
      >[/color]

      Comment

      • Rolf Wester

        #4
        Re: Beginners problem

        Kevin Thorpe wrote:
        [color=blue]
        >
        > Very common problem this. You have register_global s turned off, it's the
        > default in recent releases of php.
        >
        > replace
        > echo $firstname;
        > with
        > echo $_POST['firstname'];
        > and all will be well
        >[/color]
        Thanks a lot. It works now. Is it possible to turn register_global s on
        and if so how can I do it?

        Regards

        Rolf Wester

        Comment

        • Richard Grove

          #5
          Re: Beginners problem

          <sanya@fan.astr al.ntu-kpi.kiev.ua> wrote in message
          news:2003103119 0557.11a9cf70.s anya@fan.astral .ntu-kpi.kiev.ua...[color=blue]
          > On Fri, 31 Oct 2003 17:53:45 +0100
          > Rolf Wester <wester@ilt.fra unhofer.de> wrote:
          >[color=green]
          > > Hi,
          > >
          > > I'm just beginning PHP programming. I have installed Apache 2.0.48 and
          > > PHP 4.3.3. The installation went well. Then I was trying a little[/color][/color]
          example.[color=blue][color=green]
          > >
          > > HTML page:
          > >
          > > <html>
          > > <head>
          > > <title>test</title>
          > > </head>
          > >
          > > <body>
          > >
          > > <form action="test.ph p" method=POST>
          > > First Name: <input type=text name=firstname size=30
          > > MAXLENGTH=150>
          > > <input type=submit value="Send">
          > > </form>
          > >
          > > </body>
          > > </html>
          > >
          > > and the PHP script "test.php":
          > >
          > > <?php
          > > echo "First Name = ";
          > > echo $firstname;
          > > echo ".";
          > > ?>[/color]
          > /////////////////////////////////////////////////////////
          > in php.ini register_global s = On or use $HTTP_POST_VARS["firstname"]
          > ////////////////////////////////////////////////////////
          >[color=green]
          > >
          > > When I insert "Rolf" into the textfield and hit the "Send" button I get
          > > the response:
          > >
          > > First Name = .
          > >
          > > Nothing else. I thought that the variable $firstname is set to the
          > > string I inserted into the text field. Did I do anything wrong or could
          > > there be a problem with apache or php? I would be very appreciative for
          > > help on this problem.
          > >
          > > Regards
          > >
          > > Rolf Wester
          > >
          > > P.S.: When using method GET the form calls:
          > > http://localhost:8080/test.php?firstname=Rolf
          > > The Response is the same as before.
          > >
          > >[/color][/color]



          I wouldn't do that if I were you.
          It's best to get into good habits from the start.
          Globals on is a security risk.

          Regards
          Richard Grove



          Become a Shop Builder re-seller:
          Affiliate marketing is a simple way to earn money online, using our affiliate platform. Join a global community of publishers and advertisers.



          Comment

          • Rolf Wester

            #6
            Re: Beginners problem

            Hi,

            thanks to all for your help. I would like to turn on register_global s
            mainly for the purpose of trying some sample-scripts downloaded from
            somewhere that rely on this. I will use the more secure option
            $_POST['**'] for my own scripts.

            Regards

            Rolf Wester

            Comment

            Working...