get method

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

    get method

    I'm doing some tutorials with the book: PHP by example. The following
    program should according to the book, generates a personalized
    greeting for a visitor, but it doesn't. Any ideas why? Here's the
    code, in two seperate files:

    FIRST FILE (TEST1.PHP):

    <html>
    <head><title>We lcome!</title></head>
    <body>

    <form action="ch03ex1 1.php">

    What's your name? <input type="text" name="userName" >
    <input type="submit" value="Continue ">

    </form>

    </body>
    </html>


    SECOND FILE (CH02EX11.PHP):


    <html>
    <head><title>We lcome!<title></head>
    <body>

    <h4>
    Welcome, <?= $HTTP_get_VARS['name'] ?>!
    </h4>

    </body>
    </html>
  • Andreas Paasch

    #2
    Re: get method

    Pierre wrote:
    [color=blue]
    > I'm doing some tutorials with the book: PHP by example. The following
    > program should according to the book, generates a personalized
    > greeting for a visitor, but it doesn't. Any ideas why? Here's the
    > code, in two seperate files:
    >
    > FIRST FILE (TEST1.PHP):
    >
    > <html>
    > <head><title>We lcome!</title></head>
    > <body>
    >
    > <form action="ch03ex1 1.php">
    >
    > What's your name? <input type="text" name="userName" >
    > <input type="submit" value="Continue ">
    >
    > </form>
    >
    > </body>
    > </html>
    >
    >
    > SECOND FILE (CH02EX11.PHP):
    >
    >
    > <html>
    > <head><title>We lcome!<title></head>
    > <body>
    >
    > <h4>
    > Welcome, <?= $HTTP_get_VARS['name'] ?>!
    > </h4>
    >
    > </body>
    > </html>[/color]


    Most likely because register_global s in php.ini is set to off.

    Try to modify your code like this:

    Page 1:

    <Form action="ch03ex1 1.php" method="POST">

    Page 2:

    Welcome, <?php echo $_POST["userName"]; ?>

    .... i don't use shorttags, I go long tags thus <?php ...


    HTH,

    /Andreas
    --
    Peace and long life ...
    Registeret Linux user #292411

    Comment

    • Andreas Paasch

      #3
      Re: get method

      Andreas Paasch wrote:
      [color=blue]
      > Pierre wrote:
      >[color=green]
      >> I'm doing some tutorials with the book: PHP by example. The following
      >> program should according to the book, generates a personalized
      >> greeting for a visitor, but it doesn't. Any ideas why? Here's the
      >> code, in two seperate files:
      >>
      >> FIRST FILE (TEST1.PHP):
      >>
      >> <html>
      >> <head><title>We lcome!</title></head>
      >> <body>
      >>
      >> <form action="ch03ex1 1.php">
      >>
      >> What's your name? <input type="text" name="userName" >
      >> <input type="submit" value="Continue ">
      >>
      >> </form>
      >>
      >> </body>
      >> </html>
      >>
      >>
      >> SECOND FILE (CH02EX11.PHP):
      >>
      >>
      >> <html>
      >> <head><title>We lcome!<title></head>
      >> <body>
      >>
      >> <h4>
      >> Welcome, <?= $HTTP_get_VARS['name'] ?>!
      >> </h4>
      >>
      >> </body>
      >> </html>[/color]
      >
      >
      > Most likely because register_global s in php.ini is set to off.
      >
      > Try to modify your code like this:
      >
      > Page 1:
      >
      > <Form action="ch03ex1 1.php" method="POST">
      >
      > Page 2:
      >
      > Welcome, <?php echo $_POST["userName"]; ?>
      >
      > ... i don't use shorttags, I go long tags thus <?php ...
      >
      >
      > HTH,
      >
      > /Andreas[/color]

      Oh yes ...

      if you want it to use GET, just replace POST with GET.

      /Andreas
      --
      Peace and long life ...
      Registeret Linux user #292411

      Comment

      • Agelmar

        #4
        Re: get method

        "Andreas Paasch" <Andreas@Paasch .Net> wrote in message
        news:qor4c.1097 09$jf4.6583080@ news000.worldon line.dk...[color=blue]
        > Pierre wrote:
        >[color=green]
        > > I'm doing some tutorials with the book: PHP by example. The following
        > > program should according to the book, generates a personalized
        > > greeting for a visitor, but it doesn't. Any ideas why? Here's the
        > > code, in two seperate files:
        > >
        > > FIRST FILE (TEST1.PHP):
        > >
        > > <html>
        > > <head><title>We lcome!</title></head>
        > > <body>
        > >
        > > <form action="ch03ex1 1.php">
        > >
        > > What's your name? <input type="text" name="userName" >
        > > <input type="submit" value="Continue ">
        > >
        > > </form>
        > >
        > > </body>
        > > </html>
        > >
        > >
        > > SECOND FILE (CH02EX11.PHP):
        > >
        > >
        > > <html>
        > > <head><title>We lcome!<title></head>
        > > <body>
        > >
        > > <h4>
        > > Welcome, <?= $HTTP_get_VARS['name'] ?>!
        > > </h4>
        > >
        > > </body>
        > > </html>[/color]
        >
        >
        > Most likely because register_global s in php.ini is set to off.[/color]

        Actually, the way that the poster is doing is still ok for register_global s
        = off. This was the way prior to 4.1.0 ($HTTP_GET_VARS , $HTTP_POST_VARS ).
        But to the poster: As of 4.2.x, these are now depreciated, and you should
        use $_GET, $_POST etc instead.


        The problem with the poster's code is that the form didn't specify a method.
        If you want to use GET vars, then you need to do <form method="get"
        action="whateve r">. You can't leave out the method.


        Comment

        • John Dunlop

          #5
          Re: get method

          Agelmar wrote:
          [color=blue][color=green]
          > > Pierre wrote:
          > >[color=darkred]
          > > > <input type="text" name="userName" >[/color][/color][/color]

          [ ... ]
          [color=blue][color=green][color=darkred]
          > > > Welcome, <?= $HTTP_get_VARS['name'] ?>![/color][/color][/color]

          There's two typos there, I think, or is that really how your book
          reads? The name of your INPUT is "userName", not "name", so your
          array key ought to be "userName". Variable names are case sensitive,
          so the array name is $HTTP_GET_VARS, not $HTTP_get_VARS.
          [color=blue]
          > The problem with the poster's code is that the form didn't specify a method.
          > If you want to use GET vars, then you need to do <form method="get"
          > action="whateve r">. You can't leave out the method.[/color]

          No. GET is the default value for the method attribute; if the method
          attribute is omitted, GET is inferred.

          --
          Jock

          Comment

          • Reply Via Newsgroup

            #6
            Re: get method

            Pierre wrote:[color=blue]
            > I'm doing some tutorials with the book: PHP by example. The following
            > program should according to the book, generates a personalized
            > greeting for a visitor, but it doesn't. Any ideas why? Here's the
            > code, in two seperate files:
            >
            > FIRST FILE (TEST1.PHP):
            >
            > <html>
            > <head><title>We lcome!</title></head>
            > <body>
            >
            > <form action="ch03ex1 1.php">
            >
            > What's your name? <input type="text" name="userName" >
            > <input type="submit" value="Continue ">
            >
            > </form>
            >
            > </body>
            > </html>
            >
            >
            > SECOND FILE (CH02EX11.PHP):
            >
            >
            > <html>
            > <head><title>We lcome!<title></head>
            > <body>
            >
            > <h4>
            > Welcome, <?= $HTTP_get_VARS['name'] ?>!
            > </h4>
            >
            > </body>
            > </html>[/color]


            Your form - when submitted, calls ch03ex11.php but the second file
            you've submitted, you say is called cho02ex11.php

            Thus - you've not said 'how' its not working (ie does it complain that a
            file is missing, or some other text message perhaps belonging to a
            different script?

            The rest of the code is fine so I think its just a typo.

            Hope the above helps, and stay with PHP - once you walk, you'll soon
            learn to run...

            laters
            randell d.

            Comment

            Working...