By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,662 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

PHP and forms

P: n/a
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="HandleForm.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
Jul 16 '05 #1
Share this Question
Share on Google+
17 Replies


P: n/a
On 4 Sep 2003 12:11:02 -0700 in
<message-id:f5**************************@posting.google.com >
la*****@yahoo.com (Andrew Clark) wrote:
[ snip ]

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

TIA,
andrew

Bluntly? RTFM!

More useful.. see http://www.php.net/ regarding 'register_globals' 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.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #2

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

echo $_POST['first'];

"Andrew Clark" <la*****@yahoo.com> wrote in message
news:f5**************************@posting.google.c om...
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="HandleForm.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

Jul 16 '05 #3

P: n/a
Jon wrote:
As Ian said...Read the manual...but, to offer a place to start, check out
the following example:

echo $_POST['first'];

"Andrew Clark" <la*****@yahoo.com> wrote in message
news:f5**************************@posting.google.c om...
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="HandleForm.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



As a reply to Ian, Jon and Andrew:

I have the same problem. I tried the following:

1) Set register_globals 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
Jul 16 '05 #4

P: n/a
Andrew Clark wrote:
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="HandleForm.php" METHOD=POST>
I had success with GET instead of 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
$first=$HTTP_GET_VARS["first"];
$last=$HTTP_GET_VARS["last"];
$email=$HTTP_GET_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.
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


Bye
Karl

Jul 16 '05 #5

P: n/a
On Sat, 06 Sep 2003 12:54:12 +0200 in
<message-id:bj*************@news.t-online.com>
Karl Sarnow <ka**@dadoka.h.ni.schule.de> wrote:

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

I am using PHP 4.2.2.

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.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #6

P: n/a
Ian.H [dS] wrote:


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)).


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

Jul 16 '05 #7

P: n/a
On Sat, 06 Sep 2003 14:27:48 GMT, "Ian.H [dS]" <ia*@WINDOZEdigiserv.net> wrote:
<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)).


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

http://www.w3.org/TR/html4/interact/...ml#adef-method

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.

http://www.w3.org/TR/xhtml1/#h-4.11

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 16 '05 #8

P: n/a
KAH
Karl Sarnow <ka**@dadoka.h.ni.schule.de> wrote in news:bjceck$2qa$02$1
@news.t-online.com:
I had success with GET instead of POST.
You probably messed something up then. Show us your code.
Should work now.

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

I am using PHP 4.2.2.


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
Jul 16 '05 #9

P: n/a
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
<Xn*********************************@193.213.112.1 9> with its hoof:
[...]
By the way, in PHP 4.1+ $HTTP_*_VARS is deprecated, use the $_*
superglobals instead.

KAH


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

Does PHP 5 have $HTTP_*_VARS ?

Jul 16 '05 #10

P: n/a
On Sun, 07 Sep 2003 21:57:29 GMT in
<message-id:pa********************************@REMOVE.MEear thlink.INVAL
ID>
Gary Petersen <ga*******@remove.meearthlink.invalid> wrote:
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<Xn*********************************@193.213 .112.19> with its
hoof:
[...]
By the way, in PHP 4.1+ $HTTP_*_VARS is deprecated, use the $_*
superglobals instead.

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

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


Does PHP 5 have $HTTP_*_VARS ?

Can't answer that one =)

Regards,

Ian

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #11

P: n/a
Ian.H [dS] wrote:
On Sat, 06 Sep 2003 12:54:12 +0200 in
<message-id:bj*************@news.t-online.com>
Karl Sarnow <ka**@dadoka.h.ni.schule.de> wrote:
It seems that the POST method is buggy or not implemented.

I am using PHP 4.2.2.


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,
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

Jul 16 '05 #12

P: n/a
KAH wrote:
Karl Sarnow <ka**@dadoka.h.ni.schule.de> wrote in news:bjceck$2qa$02$1
@news.t-online.com:

I had success with GET instead of POST.

You probably messed something up then. Show us your code.


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.
Should work now.

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

I am using PHP 4.2.2.

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.


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.
By the way, in PHP 4.1+ $HTTP_*_VARS is deprecated, use the $_*
superglobals instead.

KAH


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

Karl

Jul 16 '05 #13

P: n/a
KAH
Karl Sarnow <ka**@dadoka.h.ni.schule.de> wrote in
news:bj*************@news.t-online.com:
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.
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?
Uuh, more than 100%?
Sorry for the exageration, but I wanted to highlight that this was
certainly not a PHP implementation error.
For sure my experience is less than 100%.
I doubt anyone can ever get 100% experience :-)) One always learns
something new.
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.


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
Jul 16 '05 #14

P: n/a
KAH wrote:
Karl Sarnow <ka**@dadoka.h.ni.schule.de> wrote in
news:bj*************@news.t-online.com:

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.

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?


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

....

May be this is not a problem of PHP, but of Apache. But so far I was
not able to locate the error.

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


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
Jul 16 '05 #15

P: n/a
Wm
"Karl Sarnow" <ka**@dadoka.h.ni.schule.de> wrote in message
news:bj*************@news.t-online.com...

$first=$HTTP_GET_VARS["first"];
$last=$HTTP_GET_VARS["last"];
$email=$HTTP_GET_VARS["email"];
$comments=$HTTP_GET_VARS["comments"];

Should work now.

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


I prefer POST as it avoids a long URL string (which is messy in my
logs/stats). I just start the form that receives the data with
extract($_POST).

Wm

Jul 16 '05 #16

P: n/a
"Karl Sarnow" <ka**@dadoka.h.ni.schule.de> wrote in message
news:bj*************@news.t-online.com...
<snip>
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.


Look at the output from php_info for gpc_order.

IIRC, this is in the documentation.

Cheers.

Bill Segraves


Jul 16 '05 #17

P: n/a
KAH
Karl Sarnow <ka**@dadoka.h.ni.schule.de> wrote in news:bjihfe$icb$00$1
@news.t-online.com:
How can a POST be disallowed? I did not set any special flag on my
directory. Just an ordinary public_html subdirectory. 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.


Look for <Limit> directives in httpd.conf and any .htaccess files that
might affect the directory. Example:

<Limit GET POST OPTIONS PROPFIND>
Order allow,deny
Allow from all
</Limit>

KAH
Jul 16 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.