PHP and forms

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

    PHP and forms

    i have a simple test form and a php script that handles it. the form
    is not passing the data to the script, so i end up with an empty html
    file on submit.

    the form's setup is like this -

    <FORM ACTION="HandleF orm.php" METHOD=POST>
    <TABLE>
    <TR>
    <TD>First Name:</TD>
    <TD><INPUT TYPE="text" NAME="first" SIZE=20></TD>
    </TR>
    <TR>
    <TD>Last Name:</TD>
    <TD><INPUT TYPE="text" NAME="last" SIZE=20></TD>
    </TR>
    <TR>
    <TD>Email Address:</TD>
    <TD><INPUT TYPE="text" NAME="email" SIZE=30></TD>
    </TR>
    <TR>
    <TD>Comments: </TD>
    <TD>
    <TEXTAREA NAME="comments" ROWS=5 COLS=40></TEXTAREA>
    </TD>
    </TR>
    <TR>
    <TD>
    <CENTER>
    <INPUT TYPE="submit" NAME="submit" VALUE="Submit">
    </CENTER>
    </TD>
    </TR>
    </TABLE>

    and the script -

    <HTML>
    <HEAD>
    <TITLE>Form Results</TITLE>
    </HEAD>
    <BODY>
    <?php
    print ("Your first name is $first.<BR>\n") ;
    print ("Your last name is $last.<BR>\n");
    print ("Your Email is <A
    HREF=\"mailto:$ email\">$email</A>.<BR>\n");
    print ("This is what you had to
    say:<BR><BR>\n< I>$comments</I><BR>\n");
    ?>
    </BODY>
    </HTML>

    i'm sort of new at this, so comments would be appreciated.

    TIA,
    andrew
  • Ian.H [dS]

    #2
    Re: PHP and forms

    On 4 Sep 2003 12:11:02 -0700 in
    <message-id:f54be1d8.030 9041111.1c24e7e 0@posting.googl e.com>
    lark047@yahoo.c om (Andrew Clark) wrote:


    [ snip ]

    [color=blue]
    > i'm sort of new at this, so comments would be appreciated.
    >
    > TIA,
    > andrew[/color]


    Bluntly? RTFM!

    More useful.. see http://www.php.net/ regarding 'register_globa ls' and
    their security implications.

    Try:


    echo $_POST['first'];


    for example. Also, your HTML needs addressing (strongly advised to quote
    element values).. but that is a non-PHP related issue =)


    HTH.



    Regards,

    Ian

    --
    Ian.H [Design & Development]
    digiServ Network - Web solutions
    www.digiserv.net | irc.digiserv.ne t | forum.digiserv. net
    Programming, Web design, development & hosting.

    Comment

    • Jon

      #3
      Re: PHP and forms

      As Ian said...Read the manual...but, to offer a place to start, check out
      the following example:

      echo $_POST['first'];



      "Andrew Clark" <lark047@yahoo. com> wrote in message
      news:f54be1d8.0 309041111.1c24e 7e0@posting.goo gle.com...[color=blue]
      > i have a simple test form and a php script that handles it. the form
      > is not passing the data to the script, so i end up with an empty html
      > file on submit.
      >
      > the form's setup is like this -
      >
      > <FORM ACTION="HandleF orm.php" METHOD=POST>
      > <TABLE>
      > <TR>
      > <TD>First Name:</TD>
      > <TD><INPUT TYPE="text" NAME="first" SIZE=20></TD>
      > </TR>
      > <TR>
      > <TD>Last Name:</TD>
      > <TD><INPUT TYPE="text" NAME="last" SIZE=20></TD>
      > </TR>
      > <TR>
      > <TD>Email Address:</TD>
      > <TD><INPUT TYPE="text" NAME="email" SIZE=30></TD>
      > </TR>
      > <TR>
      > <TD>Comments: </TD>
      > <TD>
      > <TEXTAREA NAME="comments" ROWS=5 COLS=40></TEXTAREA>
      > </TD>
      > </TR>
      > <TR>
      > <TD>
      > <CENTER>
      > <INPUT TYPE="submit" NAME="submit" VALUE="Submit">
      > </CENTER>
      > </TD>
      > </TR>
      > </TABLE>
      >
      > and the script -
      >
      > <HTML>
      > <HEAD>
      > <TITLE>Form Results</TITLE>
      > </HEAD>
      > <BODY>
      > <?php
      > print ("Your first name is $first.<BR>\n") ;
      > print ("Your last name is $last.<BR>\n");
      > print ("Your Email is <A
      > HREF=\"mailto:$ email\">$email</A>.<BR>\n");
      > print ("This is what you had to
      > say:<BR><BR>\n< I>$comments</I><BR>\n");
      > ?>
      > </BODY>
      > </HTML>
      >
      > i'm sort of new at this, so comments would be appreciated.
      >
      > TIA,
      > andrew[/color]


      Comment

      • Karl Sarnow

        #4
        Re: PHP and forms

        Jon wrote:[color=blue]
        > As Ian said...Read the manual...but, to offer a place to start, check out
        > the following example:
        >
        > echo $_POST['first'];
        >
        >
        >
        > "Andrew Clark" <lark047@yahoo. com> wrote in message
        > news:f54be1d8.0 309041111.1c24e 7e0@posting.goo gle.com...
        >[color=green]
        >>i have a simple test form and a php script that handles it. the form
        >>is not passing the data to the script, so i end up with an empty html
        >>file on submit.
        >>
        >>the form's setup is like this -
        >>
        >> <FORM ACTION="HandleF orm.php" METHOD=POST>
        >> <TABLE>
        >> <TR>
        >> <TD>First Name:</TD>
        >> <TD><INPUT TYPE="text" NAME="first" SIZE=20></TD>
        >> </TR>
        >> <TR>
        >> <TD>Last Name:</TD>
        >> <TD><INPUT TYPE="text" NAME="last" SIZE=20></TD>
        >> </TR>
        >> <TR>
        >> <TD>Email Address:</TD>
        >> <TD><INPUT TYPE="text" NAME="email" SIZE=30></TD>
        >> </TR>
        >> <TR>
        >> <TD>Comments: </TD>
        >> <TD>
        >> <TEXTAREA NAME="comments" ROWS=5 COLS=40></TEXTAREA>
        >> </TD>
        >> </TR>
        >> <TR>
        >> <TD>
        >> <CENTER>
        >> <INPUT TYPE="submit" NAME="submit" VALUE="Submit">
        >> </CENTER>
        >> </TD>
        >> </TR>
        >> </TABLE>
        >>
        >>and the script -
        >>
        >><HTML>
        >> <HEAD>
        >> <TITLE>Form Results</TITLE>
        >> </HEAD>
        >> <BODY>
        >><?php
        >> print ("Your first name is $first.<BR>\n") ;
        >> print ("Your last name is $last.<BR>\n");
        >> print ("Your Email is <A
        >>HREF=\"mailto :$email\">$emai l</A>.<BR>\n");
        >> print ("This is what you had to
        >>say:<BR><BR>\ n<I>$comments</I><BR>\n");
        >>?>
        >> </BODY>
        >></HTML>
        >>
        >>i'm sort of new at this, so comments would be appreciated.
        >>
        >>TIA,
        >>andrew[/color]
        >
        >
        >[/color]

        As a reply to Ian, Jon and Andrew:

        I have the same problem. I tried the following:

        1) Set register_global s in /etc/php.ini to On.
        2) Tried $variable=$HTTP _POST_VARS['variable'];
        3) Tried $_POST['variable'];

        Nothing works.

        I did not find any helpful information in the doc files.

        Any idea now?

        Thanks
        Karl


        Comment

        • Karl Sarnow

          #5
          Re: PHP and forms

          Andrew Clark wrote:[color=blue]
          > i have a simple test form and a php script that handles it. the form
          > is not passing the data to the script, so i end up with an empty html
          > file on submit.
          >
          > the form's setup is like this -
          >
          > <FORM ACTION="HandleF orm.php" METHOD=POST>[/color]

          I had success with GET instead of POST.
          [color=blue]
          > <TABLE>
          > <TR>
          > <TD>First Name:</TD>
          > <TD><INPUT TYPE="text" NAME="first" SIZE=20></TD>
          > </TR>
          > <TR>
          > <TD>Last Name:</TD>
          > <TD><INPUT TYPE="text" NAME="last" SIZE=20></TD>
          > </TR>
          > <TR>
          > <TD>Email Address:</TD>
          > <TD><INPUT TYPE="text" NAME="email" SIZE=30></TD>
          > </TR>
          > <TR>
          > <TD>Comments: </TD>
          > <TD>
          > <TEXTAREA NAME="comments" ROWS=5 COLS=40></TEXTAREA>
          > </TD>
          > </TR>
          > <TR>
          > <TD>
          > <CENTER>
          > <INPUT TYPE="submit" NAME="submit" VALUE="Submit">
          > </CENTER>
          > </TD>
          > </TR>
          > </TABLE>
          >
          > and the script -
          >
          > <HTML>
          > <HEAD>
          > <TITLE>Form Results</TITLE>
          > </HEAD>
          > <BODY>
          > <?php[/color]

          $first=$HTTP_GE T_VARS["first"];
          $last=$HTTP_GET _VARS["last"];
          $email=$HTTP_GE T_VARS["email"];
          $comments=$HTTP _GET_VARS["comments"];

          Should work now.

          It seems that the POST method is buggy or not implemented.

          I am using PHP 4.2.2.
          [color=blue]
          > print ("Your first name is $first.<BR>\n") ;
          > print ("Your last name is $last.<BR>\n");
          > print ("Your Email is <A
          > HREF=\"mailto:$ email\">$email</A>.<BR>\n");
          > print ("This is what you had to
          > say:<BR><BR>\n< I>$comments</I><BR>\n");
          > ?>
          > </BODY>
          > </HTML>
          >
          > i'm sort of new at this, so comments would be appreciated.
          >
          > TIA,
          > andrew[/color]

          Bye
          Karl

          Comment

          • Ian.H [dS]

            #6
            Re: PHP and forms

            On Sat, 06 Sep 2003 12:54:12 +0200 in
            <message-id:bjceck$2qa$0 2$1@news.t-online.com>
            Karl Sarnow <karl@dadoka.h. ni.schule.de> wrote:

            [color=blue]
            > It seems that the POST method is buggy or not implemented.
            >
            > I am using PHP 4.2.2.[/color]


            Forms run perfectly fine using $_POST on my server, which ironically, is
            running PHP 4.2.2 still ;)

            Personally, I think the HTML needs fixing first, then figure out the PHP
            biz'....


            <form method="post" action="/path/to/foo.php">


            Yes, elements _should_ be quoted.. and lowercase is recommended,
            although not a necessity (I'm assuming PHP handles 'POST' aswell as
            'post' (I've never tried)).



            Regards,

            Ian

            --
            Ian.H [Design & Development]
            digiServ Network - Web solutions
            www.digiserv.net | irc.digiserv.ne t | forum.digiserv. net
            Programming, Web design, development & hosting.

            Comment

            • matty

              #7
              Re: PHP and forms

              Ian.H [dS] wrote:

              [color=blue]
              >
              > Yes, elements _should_ be quoted.. and lowercase is recommended,
              > although not a necessity (I'm assuming PHP handles 'POST' aswell as
              > 'post' (I've never tried)).
              >
              >
              >[/color]

              POST is something for the browser, not PHP, so it should handle OK
              either way.

              Comment

              • Andy Hassall

                #8
                Re: PHP and forms

                On Sat, 06 Sep 2003 14:27:48 GMT, "Ian.H [dS]" <ian@WINDOZEdig iserv.net> wrote:
                [color=blue]
                > <form method="post" action="/path/to/foo.php">
                >
                >Yes, elements _should_ be quoted.. and lowercase is recommended,
                >although not a necessity (I'm assuming PHP handles 'POST' aswell as
                >'post' (I've never tried)).[/color]

                Most HTML attribute values are case-insensitive. form method certainly is.



                However in XHTML they are case-sensitive; all element and attribute names must
                be lower-case, and all attribute values which are part of a pre-defined value
                set (i.e. 'get', 'post') must be lower-case.



                --
                Andy Hassall (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
                Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

                Comment

                • KAH

                  #9
                  Re: PHP and forms

                  Karl Sarnow <karl@dadoka.h. ni.schule.de> wrote in news:bjceck$2qa $02$1
                  @news.t-online.com:
                  [color=blue]
                  > I had success with GET instead of POST.[/color]

                  You probably messed something up then. Show us your code.
                  [color=blue]
                  > Should work now.
                  >
                  > It seems that the POST method is buggy or not implemented.
                  >
                  > I am using PHP 4.2.2.[/color]

                  I think you need to get a bit more PHP experience before you start
                  answering questions. This is 101% incorrect, the POST method is neither
                  buggy or not implemented.

                  By the way, in PHP 4.1+ $HTTP_*_VARS is deprecated, use the $_*
                  superglobals instead.

                  KAH

                  Comment

                  • Gary Petersen

                    #10
                    Re: PHP and forms

                    A horsie named KAH demonstrated surprising intellligence and its ability
                    to use morse code on Sun, 07 Sep 2003 07:00:44 -0500 when it tapped
                    <Xns93EF8F1C9E8 0kahatkahnewsdo tcjbdo@193.213. 112.19> with its hoof:
                    [color=blue]
                    > [...]
                    > By the way, in PHP 4.1+ $HTTP_*_VARS is deprecated, use the $_*
                    > superglobals instead.
                    >
                    > KAH[/color]

                    Do you mean that $HTTP_*_VARS will be removed at some point?

                    Does PHP 5 have $HTTP_*_VARS ?

                    Comment

                    • Ian.H [dS]

                      #11
                      Re: PHP and forms

                      On Sun, 07 Sep 2003 21:57:29 GMT in
                      <message-id:pan.2003.09. 07.18.44.01.358 655.334@REMOVE. MEearthlink.INV AL
                      ID>
                      Gary Petersen <garyp1492@remo ve.meearthlink. invalid> wrote:
                      [color=blue]
                      > A horsie named KAH demonstrated surprising intellligence and its
                      > ability to use morse code on Sun, 07 Sep 2003 07:00:44 -0500 when it
                      > tapped<Xns93EF8 F1C9E80kahatkah newsdotcjbdo@19 3.213.112.19> with its
                      > hoof:
                      >[color=green]
                      > > [...]
                      > > By the way, in PHP 4.1+ $HTTP_*_VARS is deprecated, use the $_*
                      > > superglobals instead.
                      > >
                      > > KAH[/color]
                      >
                      > Do you mean that $HTTP_*_VARS will be removed at some point?[/color]


                      Apparently so, this was used for pre-4.2.0 versions of PHP as those
                      versions didn't include things like $_GET / $_POST superglobals.

                      [color=blue]
                      >
                      > Does PHP 5 have $HTTP_*_VARS ?
                      >[/color]


                      Can't answer that one =)



                      Regards,

                      Ian

                      --
                      Ian.H [Design & Development]
                      digiServ Network - Web solutions
                      www.digiserv.net | irc.digiserv.ne t | forum.digiserv. net
                      Programming, Web design, development & hosting.

                      Comment

                      • Karl Sarnow

                        #12
                        Re: PHP and forms

                        Ian.H [dS] wrote:[color=blue]
                        > On Sat, 06 Sep 2003 12:54:12 +0200 in
                        > <message-id:bjceck$2qa$0 2$1@news.t-online.com>
                        > Karl Sarnow <karl@dadoka.h. ni.schule.de> wrote:
                        >
                        >
                        >[color=green]
                        >> It seems that the POST method is buggy or not implemented.
                        >>
                        >> I am using PHP 4.2.2.[/color]
                        >
                        >
                        >
                        > Forms run perfectly fine using $_POST on my server, which ironically, is
                        > running PHP 4.2.2 still ;)
                        >
                        > Personally, I think the HTML needs fixing first, then figure out the PHP
                        > biz'....
                        >
                        >
                        > <form method="post" action="/path/to/foo.php">
                        >
                        >
                        > Yes, elements _should_ be quoted.. and lowercase is recommended,
                        > although not a necessity (I'm assuming PHP handles 'POST' aswell as
                        > 'post' (I've never tried)).
                        >
                        >
                        >
                        > Regards,
                        >
                        > Ian
                        >[/color]

                        Ian,
                        I am running PHP on an APACHE Webserver. May be this is the difference.
                        At least absolut paths are not allowed. Only relative ones to the actual
                        web location.

                        In all former versions of PHP I never had a problem with post. But in
                        this version, I do have. I so far cannot say whether it is PHP or APACHE
                        which plays games on me.

                        Karl

                        Comment

                        • Karl Sarnow

                          #13
                          Re: PHP and forms

                          KAH wrote:[color=blue]
                          > Karl Sarnow <karl@dadoka.h. ni.schule.de> wrote in news:bjceck$2qa $02$1
                          > @news.t-online.com:
                          >
                          >[color=green]
                          >>I had success with GET instead of POST.[/color]
                          >
                          >
                          > You probably messed something up then. Show us your code.
                          >[/color]

                          I used the same code, once with mehtod GET once with method POST: The
                          first method works, the second does not.

                          As far as I can see, I was able to spell GET and POST and let the rest
                          as it was.

                          See the code in the first posting.[color=blue]
                          >[color=green]
                          >>Should work now.
                          >>
                          >>It seems that the POST method is buggy or not implemented.
                          >>
                          >>I am using PHP 4.2.2.[/color]
                          >
                          >
                          > I think you need to get a bit more PHP experience before you start
                          > answering questions. This is 101% incorrect, the POST method is neither
                          > buggy or not implemented.
                          >[/color]

                          Uuh, more than 100%?

                          For sure my experience is less than 100%.

                          I answered a question, which was not answered in a way, I could have
                          used. But I had the same experience as the person having posted the
                          question. So i hope this helped him.

                          I have not experienced a similar behaviour in any PHP version before. So
                          at this very first step, I can only say that the same code with GET
                          works in my environment, while the same code with POST does not.

                          May be this is not a problem of PHP, but of Apache. But so far I was not
                          able to locate the error.
                          [color=blue]
                          > By the way, in PHP 4.1+ $HTTP_*_VARS is deprecated, use the $_*
                          > superglobals instead.
                          >
                          > KAH[/color]

                          Did that with the same results: Works for GET, works not for POST.

                          Karl

                          Comment

                          • KAH

                            #14
                            Re: PHP and forms

                            Karl Sarnow <karl@dadoka.h. ni.schule.de> wrote in
                            news:bji8o4$etu $05$1@news.t-online.com:
                            [color=blue]
                            > I used the same code, once with mehtod GET once with method POST: The
                            > first method works, the second does not.
                            >
                            > As far as I can see, I was able to spell GET and POST and let the rest
                            > as it was.
                            >
                            > See the code in the first posting.[/color]

                            In that case, it's probably a snag with your server or browser (wouldn't
                            surprise me, his HTML is bad). Perhaps POST is disallowed in the
                            directory you tested from?
                            [color=blue]
                            > Uuh, more than 100%?[/color]

                            Sorry for the exageration, but I wanted to highlight that this was
                            certainly not a PHP implementation error.
                            [color=blue]
                            > For sure my experience is less than 100%.[/color]

                            I doubt anyone can ever get 100% experience :-)) One always learns
                            something new.
                            [color=blue]
                            > I answered a question, which was not answered in a way, I could have
                            > used. But I had the same experience as the person having posted the
                            > question. So i hope this helped him.
                            >
                            > I have not experienced a similar behaviour in any PHP version before.
                            > So at this very first step, I can only say that the same code with GET
                            > works in my environment, while the same code with POST does not.
                            >
                            > May be this is not a problem of PHP, but of Apache. But so far I was
                            > not able to locate the error.[/color]

                            I've never heard of this before, the only thing that springs to mind is
                            permissions in the Apache config. If POST is allowed, then I'm at loss.

                            KAH

                            Comment

                            • Karl Sarnow

                              #15
                              Re: PHP and forms

                              KAH wrote:[color=blue]
                              > Karl Sarnow <karl@dadoka.h. ni.schule.de> wrote in
                              > news:bji8o4$etu $05$1@news.t-online.com:
                              >
                              >[color=green]
                              >>I used the same code, once with mehtod GET once with method POST: The
                              >>first method works, the second does not.
                              >>
                              >>As far as I can see, I was able to spell GET and POST and let the rest
                              >>as it was.
                              >>
                              >>See the code in the first posting.[/color]
                              >
                              >
                              > In that case, it's probably a snag with your server or browser (wouldn't
                              > surprise me, his HTML is bad). Perhaps POST is disallowed in the
                              > directory you tested from?
                              >[/color]

                              How can a POST be disallowed? I did not set any special flag on my
                              directory. Just an ordinary public_html subdirectory.

                              ....
                              [color=blue][color=green]
                              >>
                              >>May be this is not a problem of PHP, but of Apache. But so far I was
                              >>not able to locate the error.[/color]
                              >
                              >
                              > I've never heard of this before, the only thing that springs to mind is
                              > permissions in the Apache config. If POST is allowed, then I'm at loss.
                              >
                              > KAH[/color]

                              Where can I find the setting for POST? I looked for it but did not find
                              anything. Neither in /etc/php.ini nor in /etc/httpd/httpd.conf

                              But as the last file is quite long, may be I overlooked it. If you know
                              the name of the variable, let me know.

                              Karl


                              Comment

                              Working...