Beginner question on PHP (redhat 9) and variables

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

    Beginner question on PHP (redhat 9) and variables

    I am trying to work through a PHP book that I bought a year or so ago,
    "Essential PHP" by Christopher Cosentino. In the beginning of the
    book, after the Hello, World .php file, you get to a two-parter : a
    form that sends it's results to another .php file, that then displays
    those results.

    Nothing I have been able to do has gotten this type of passing to
    work. Checking the URL string for the second page, it properly shows
    the values :



    However, when I refer to $first_name or $address from the second .php
    file, they always render as empty (NULL). I cannot figure out why
    this relatively simple case is not working; I can define local
    variables and output them, however, I cannot pull the variables from
    the URL string, so I can't work with forms.

    I'm using a default Redhat 9 install, that came with Apache and PHP
    preconfigured. I have made a few unrelated changes to Apache (setting
    up SSL, etc) - is there something that needs to be done to get PHP to
    work with variables?

    Any ideas? I'm at my wit's end...

    Thanks a lot!

    -- Brian
  • Eric Bohlman

    #2
    Re: Beginner question on PHP (redhat 9) and variables

    brian_bibeault@ hotmail.com (Brian) wrote in
    news:a0a0ff6.04 01241531.40f734 1c@posting.goog le.com:
    [color=blue]
    > I am trying to work through a PHP book that I bought a year or so ago,
    > "Essential PHP" by Christopher Cosentino. In the beginning of the
    > book, after the Hello, World .php file, you get to a two-parter : a
    > form that sends it's results to another .php file, that then displays
    > those results.
    >
    > Nothing I have been able to do has gotten this type of passing to
    > work. Checking the URL string for the second page, it properly shows
    > the values :
    >
    > http://localhost/PHP/form_results.ph...st_name=Bibeau
    > lt&address=My+A ddress&home_pho ne=NA&submit=Su bmit+Query
    >
    > However, when I refer to $first_name or $address from the second .php
    > file, they always render as empty (NULL). I cannot figure out why
    > this relatively simple case is not working; I can define local
    > variables and output them, however, I cannot pull the variables from
    > the URL string, so I can't work with forms.[/color]

    That book probably presupposes that PHP's register_global s option is turned
    on, which it was by default in earlier versions of PHP but hasn't been for
    the last several releases. And it's generally not a good idea to turn it
    on unless you really know what you're doing. The preferred way to access
    form parameters is to use the $_GET and $_POST arrays; since in your case
    you're using the GET method (parameters passed as part of the URL), you'd
    want $_GET. Try looking at $_GET['first_name'] or $_GET['address'] and I
    think you'll find what you're looking for.

    Comment

    • Brian Bibeault

      #3
      Re: Beginner question on PHP (redhat 9) and variables

      Eric Bohlman <ebohlman@earth link.net> wrote in message news:<Xns947ABB 1F92605ebohlman omsdevcom@130.1 33.1.4>...[color=blue]
      > brian_bibeault@ hotmail.com (Brian) wrote in
      > news:a0a0ff6.04 01241531.40f734 1c@posting.goog le.com:
      >[color=green]
      > > I am trying to work through a PHP book that I bought a year or so ago,
      > > "Essential PHP" by Christopher Cosentino. In the beginning of the
      > > book, after the Hello, World .php file, you get to a two-parter : a
      > > form that sends it's results to another .php file, that then displays
      > > those results.
      > >
      > > Nothing I have been able to do has gotten this type of passing to
      > > work. Checking the URL string for the second page, it properly shows
      > > the values :
      > >
      > > http://localhost/PHP/form_results.ph...st_name=Bibeau
      > > lt&address=My+A ddress&home_pho ne=NA&submit=Su bmit+Query
      > >
      > > However, when I refer to $first_name or $address from the second .php
      > > file, they always render as empty (NULL). I cannot figure out why
      > > this relatively simple case is not working; I can define local
      > > variables and output them, however, I cannot pull the variables from
      > > the URL string, so I can't work with forms.[/color]
      >
      > That book probably presupposes that PHP's register_global s option is turned
      > on, which it was by default in earlier versions of PHP but hasn't been for
      > the last several releases. And it's generally not a good idea to turn it
      > on unless you really know what you're doing. The preferred way to access
      > form parameters is to use the $_GET and $_POST arrays; since in your case
      > you're using the GET method (parameters passed as part of the URL), you'd
      > want $_GET. Try looking at $_GET['first_name'] or $_GET['address'] and I
      > think you'll find what you're looking for.[/color]

      Thanks a lot, Eric, that was it, exactly. Too bad I didn't hear about
      this before I reinstalled Apache and PHP (but the newer version have
      other security fixes, so it wasn't wasted time).

      -- Brian

      Comment

      Working...