Problems using the $_POST[] array 
Author Message
 Problems using the $_POST[] array

Hello,

I am new to PHP, but have successfully gotten it installed and running.

The problem I have is this:

I can access form values where the method="GET" using the $_GET[] array, but
I cannot access any values using the $_POST[] array when using a form with
method="POST". I have tried running PHP with register_globals on and with it
off and cannot get values from the $_POST[] array either way. With
register_globals = On I also cannot just use the $form_field_name either.

I created another page and used the import_request_variables() function, and
was able to access all the POST-ed values. Why is this? Is this a
requirement that is not stated somewhere for accessing the POST-ed values?

I am running PHP4.2.3 on Apache 1.3.27 installed as a service under IIS 5 on
Windows 2000.

By the way (and I don't mean to be rude or snide or [pick an adjective]) but
I have been through this newsgroup 12 times, read through the PHP manual 2
dozen times, and still can't find an answer to my problem, so please don't
post "Read the manual at php.net."

Thanks,
Dave



Thu, 19 May 2005 21:12:26 GMT  
 Problems using the $_POST[] array


Quote:
> I can access form values where the method="GET" using the $_GET[]
> array, but I cannot access any values using the $_POST[] array when
> using a form with method="POST". I have tried running PHP with
> register_globals on and with it off and cannot get values from the
> $_POST[] array either way. With register_globals = On I also cannot
> just use the $form_field_name either.

Do you use $_POST[field] or $_POST["field"]/$_POST['field']? The first is
illegal syntax.

KAH



Thu, 19 May 2005 23:07:27 GMT  
 Problems using the $_POST[] array
Hi Dave

I am not sure what is going wrong with you. I have installed PHP 4.2.3,
Apache 1.3.x running on windows 2000. I am not using IIS though. I have
never had any luck with it and PHP.

Try this code. Put it at the top of the page that you post to, run it, and
then view the source. It will tell you what is in each array.
register_globals should be Off.

// these lines format the output as HTML comments

    echo "\n<!-- ********** BEGIN VARIABLE DUMP ********** -->\n\n\n";

    echo "<!-- BEGIN GET VARS -->\n";
        if (!empty($_GET)) {
            echo "<!-- ";
         print_r($_GET);
            echo "-->\n";
        } //end if
    echo "<!-- END GET VARS -->\n\n";

    echo "<!-- BEGIN POST VARS -->\n";
    if (!empty($_POST)) {
            echo "<!-- ";
         print_r($_POST);
            echo "-->\n";
        } //end if
    echo "<!-- END POST VARS -->\n\n";

    echo "<!-- BEGIN SESSION VARS -->\n";
    if (!empty($_SESSION)) {
            echo "<!-- ";
         print_r($_SESSION);
            echo "-->\n";
        } //end if
    echo "<!-- END SESSION VARS -->\n\n";

    echo "<!-- BEGIN COOKIE VARS -->\n";
    if (!empty($_COOKIE)) {
            echo "<!-- ";
         print_r($_COOKIE);
            echo "-->\n";
        } //end if
    echo "<!-- END COOKIE VARS -->\n\n\n";

    echo "<!-- ********** END VARIABLE DUMP ********** -->\n";


Quote:
> Hello,

> I am new to PHP, but have successfully gotten it installed and running.

> The problem I have is this:

> I can access form values where the method="GET" using the $_GET[] array,
but
> I cannot access any values using the $_POST[] array when using a form with
> method="POST". I have tried running PHP with register_globals on and with
it
> off and cannot get values from the $_POST[] array either way. With
> register_globals = On I also cannot just use the $form_field_name either.

> I created another page and used the import_request_variables() function,
and
> was able to access all the POST-ed values. Why is this? Is this a
> requirement that is not stated somewhere for accessing the POST-ed values?

> I am running PHP4.2.3 on Apache 1.3.27 installed as a service under IIS 5
on
> Windows 2000.

> By the way (and I don't mean to be rude or snide or [pick an adjective])
but
> I have been through this newsgroup 12 times, read through the PHP manual 2
> dozen times, and still can't find an answer to my problem, so please don't
> post "Read the manual at php.net."

> Thanks,
> Dave



Fri, 20 May 2005 00:55:07 GMT  
 Problems using the $_POST[] array
Thanks for the help Tim.

I ran your script, viewed the source and lo and behold, there they were. I
am still not sure what was going on, but I've tried doing an echo of a
variable in the form and it works as expected.

Thanks again,

Dave


Quote:
> Hi Dave

> I am not sure what is going wrong with you. I have installed PHP 4.2.3,
> Apache 1.3.x running on windows 2000. I am not using IIS though. I have
> never had any luck with it and PHP.

> Try this code. Put it at the top of the page that you post to, run it, and
> then view the source. It will tell you what is in each array.
> register_globals should be Off.

> // these lines format the output as HTML comments

>     echo "\n<!-- ********** BEGIN VARIABLE DUMP ********** -->\n\n\n";

>     echo "<!-- BEGIN GET VARS -->\n";
>         if (!empty($_GET)) {
>             echo "<!-- ";
>          print_r($_GET);
>             echo "-->\n";
>         } //end if
>     echo "<!-- END GET VARS -->\n\n";

>     echo "<!-- BEGIN POST VARS -->\n";
>     if (!empty($_POST)) {
>             echo "<!-- ";
>          print_r($_POST);
>             echo "-->\n";
>         } //end if
>     echo "<!-- END POST VARS -->\n\n";

>     echo "<!-- BEGIN SESSION VARS -->\n";
>     if (!empty($_SESSION)) {
>             echo "<!-- ";
>          print_r($_SESSION);
>             echo "-->\n";
>         } //end if
>     echo "<!-- END SESSION VARS -->\n\n";

>     echo "<!-- BEGIN COOKIE VARS -->\n";
>     if (!empty($_COOKIE)) {
>             echo "<!-- ";
>          print_r($_COOKIE);
>             echo "-->\n";
>         } //end if
>     echo "<!-- END COOKIE VARS -->\n\n\n";

>     echo "<!-- ********** END VARIABLE DUMP ********** -->\n";



> > Hello,

> > I am new to PHP, but have successfully gotten it installed and running.

> > The problem I have is this:

> > I can access form values where the method="GET" using the $_GET[] array,
> but
> > I cannot access any values using the $_POST[] array when using a form
with
> > method="POST". I have tried running PHP with register_globals on and
with
> it
> > off and cannot get values from the $_POST[] array either way. With
> > register_globals = On I also cannot just use the $form_field_name
either.

> > I created another page and used the import_request_variables() function,
> and
> > was able to access all the POST-ed values. Why is this? Is this a
> > requirement that is not stated somewhere for accessing the POST-ed
values?

> > I am running PHP4.2.3 on Apache 1.3.27 installed as a service under IIS
5
> on
> > Windows 2000.

> > By the way (and I don't mean to be rude or snide or [pick an adjective])
> but
> > I have been through this newsgroup 12 times, read through the PHP manual
2
> > dozen times, and still can't find an answer to my problem, so please
don't
> > post "Read the manual at php.net."

> > Thanks,
> > Dave



Fri, 20 May 2005 08:28:01 GMT  
 Problems using the $_POST[] array
An interesting point to note:

This worked when I created a form specifically for testing your script. Then
I went back to my original page I was having the problem with and it still
didn't work. I found that I had a "Name" field with name="name". This was
causing the problem.

Thanks again for your help,

Dave



Fri, 20 May 2005 09:06:29 GMT  
 Problems using the $_POST[] array
"Dave Scott" wrote

Quote:
> An interesting point to note:

> This worked when I created a form specifically for testing your script.
Then
> I went back to my original page I was having the problem with and it
still
> didn't work. I found that I had a "Name" field with name="name". This
was
> causing the problem.

Not really -- read KAH's reply and
http://php.net/language.types.array#language.types.array.donts

And next time show some code...

a.



Fri, 20 May 2005 17:57:14 GMT  
 Problems using the $_POST[] array
Well, in my case, even after adding Tim's code to my page and testing it
that way, it still did not work.

But when I changed the name of the name field to "fullname" instead of
"name" all the elements in the $_POST[] array became available.

I have programmed other languages before and I understand the concept of
arrays, but in my case, for whatever reason, it was not handling the
name="name" attribute properly.

Also, whenever I tried to access a POST-ed variable, I was using the syntax
$_POST["field"]; so I know it wasn't a syntax problem. The only thing I
changed after adding Tim's code was changing the field name from "name" to
"fullname". And this solved the problem.

Again, Thanks everyone for the help.

Dave



Quote:
> "Dave Scott" wrote
> > An interesting point to note:

> > This worked when I created a form specifically for testing your script.
> Then
> > I went back to my original page I was having the problem with and it
> still
> > didn't work. I found that I had a "Name" field with name="name". This
> was
> > causing the problem.

> Not really -- read KAH's reply and
> http://php.net/language.types.array#language.types.array.donts

> And next time show some code...

> a.



Sat, 21 May 2005 10:19:24 GMT  
 Problems using the $_POST[] array
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In a fit of e{*filter*}ment on Mon, 2 Dec 2002 21:19:24 -0500, "Dave Scott"

[snip]

Quote:
> But when I changed the name of the name field to "fullname" instead
> of "name" all the elements in the $_POST[] array became available.

> I have programmed other languages before and I understand the concept
> of arrays, but in my case, for whatever reason, it was not handling
> the name="name" attribute properly.

> Also, whenever I tried to access a POST-ed variable, I was using the
> syntax $_POST["field"]; so I know it wasn't a syntax problem. The
> only thing I changed after adding Tim's code was changing the field
> name from "name" to "fullname". And this solved the problem.

Maybe this isn't the issue, but my 2p worth:

I often use name="name" in forms, but instead of $_POST["name"] I use
single quotes ($_POST['name']). I personally use ' ' all the time for
the associative arrays but now just curious of the results if you were
to try that.

Just a thought.

Regards,

  Ian

-----BEGIN PGP SIGNATURE-----
Version: PGP Personal Privacy 6.5.3

iQA/AwUBPewfDGfqtj251CDhEQJMCACdHh3OdAkUkHBkSI10OLTkgUDTqxAAoK2m
pEW0VRkb9buxaxwFwpbpI5EJ
=eKh0
-----END PGP SIGNATURE-----

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



Sat, 21 May 2005 11:02:10 GMT  
 Problems using the $_POST[] array

Quote:

> Well, in my case, even after adding Tim's code to my page
> and testing it that way, it still did not work.

> But when I changed the name of the name field to "fullname"
> instead of "name" all the elements in the $_POST[] array
> became available.

Whatever you want, but either you've got a buggy browser, buggy PHP or buggy
code. Like: did you also quote the values in the HTML tags, like

  <input type="text" name="name">

rather than

  <input type=text name=name> <!-- Ai, smells like trouble -->

The following works 100% fine for me (in fact I quickly tested with an old
version, using $HTTP_POST_VARS and $HTTP_SERVER_VARS, but well), both with
single or double quotes in both the PHP and HTML code:

  <html>
    <body>
      <?php
        if(isset($_POST['name']))
          echo "Name was " . $_POST['name'];
      ?>
      <form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
        Name:
        <input type="text" name="name">
        <input type="submit">
      </form>
    </body>
  </html>

Quote:
> in my case, for whatever reason, it was not handling the
> name="name" attribute properly.

So I guess you /did/ qoute the value in the HTML elements. Hmm, I wonder
what browser and version of PHP you're using? What does the sample code
above give you then?

a.



Sat, 21 May 2005 18:18:16 GMT  
 Problems using the $_POST[] array
I am using Internet Explorer 6 SP1 for my development work with PHP 4.2.3. I
am running Apache 1.3.27 as a service under IIS5 on Windows 2000.

Here is an excerpt from the code in question (does not include the HTML for
the rest of the page. This page is called as the action="" attribute of the
form on the request page.

Arjan, you are correct, I did (and always do) put quotes around all
attribute values.

A quick question though: I used the parameters found on the PHP website for
sending HTML email, but when I open the mails in Outlook Express, I see the
code. Have I done something wrong in the headers? Or is there a better way
to specify the mail as HTML?

<?php
$dte = date("D, d M Y");
If ($_POST['formname'] == "sitedesign") {
$subject = "Site Design Quote";
$message = "<html><head><style>body{color:#000000;
font-family:tahoma,verdana,arial; font-size:10pt;} td{font-size:10pt;
padding:5px; background-color:#e9e9e9; border:1px solid
#000000;}</style><body><span style='background-color:#0077fb; color:#ffffff;
padding:5px; border:1px solid #000000;'>On ";
$message .= $dte." ".$_POST['fullname'];
$message .= " submitted the following information:</span><br><p><table
width=400 cellpadding=3 cellspacing=0 border=1><tr><td>Name:</td><td>";
$message .= $_POST['fullname']."</td></tr><td>E-Mail:</td><td>";
$message .= $_POST['email']."</td></tr><td>Co. Name</td><td>";
$message .= $_POST['coname']."</td></tr><tr><td>Site:</td><td>";
$message .= $_POST['currsite']."</td></tr><tr><td>Design Type:</td><td>";
$message .= $_POST['destype']."</td></tr><tr><td>Logo
Design<br>Rollover<br>Extra Code<br>E-Commerce<br>Other graphics</td><td>";
$message .=
$_POST['logo']."<br>".$_POST['roll']."<br>".$_POST['code']."<br>".$_POST['ec
om']."<br>".$_POST['grph'];
$message .= "</td></tr><tr><td>Other Comments:</td><td>";
$message .= $_POST['info']."</td></tr></table></body></html>";
echo
"<table><tr><td>Name:</td><td>".$_POST['fullname']."</td></tr><tr><td>E-Mail
:</td><td>".$_POST['email']."</td></tr><tr><td>Company
Name:</td><td>".$_POST['coname']."</td></tr><tr><td>Site
Address:</td><td>".$_POST['currsite']."</td></tr><tr><td>Design
Type:</td><td>".$_POST['destype']."</td></tr><tr><td>Logo:</td><td>".$_POST[
'logo']."</td></tr><tr><td>Rollover:</td><td>".$_POST['roll']."</td></tr><tr

Quote:
><td>Extra

Code:</td><td>".$_POST['code']."</td></tr><tr><td>E-Commerce:</td><td>".$_PO
ST['ecom']."</td></tr><tr><td>Graphics:</td><td>".$_POST['grph']."</td></tr>
<tr><td>Comments:</td><td>".$_POST['info']."</td></tr></table>";
Quote:
}

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ";
$headers .= $_POST['email'];

$fp = fopen("submittedforms.txt", "a");
fwrite($fp, $message);
?>



Quote:

> > Well, in my case, even after adding Tim's code to my page
> > and testing it that way, it still did not work.

> > But when I changed the name of the name field to "fullname"
> > instead of "name" all the elements in the $_POST[] array
> > became available.

> Whatever you want, but either you've got a buggy browser, buggy PHP or
buggy
> code. Like: did you also quote the values in the HTML tags, like

>   <input type="text" name="name">

> rather than

>   <input type=text name=name> <!-- Ai, smells like trouble -->

> The following works 100% fine for me (in fact I quickly tested with an old
> version, using $HTTP_POST_VARS and $HTTP_SERVER_VARS, but well), both with
> single or double quotes in both the PHP and HTML code:

>   <html>
>     <body>
>       <?php
>         if(isset($_POST['name']))
>           echo "Name was " . $_POST['name'];
>       ?>
>       <form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
>         Name:
>         <input type="text" name="name">
>         <input type="submit">
>       </form>
>     </body>
>   </html>

> > in my case, for whatever reason, it was not handling the
> > name="name" attribute properly.

> So I guess you /did/ qoute the value in the HTML elements. Hmm, I wonder
> what browser and version of PHP you're using? What does the sample code
> above give you then?

> a.



Mon, 23 May 2005 10:23:09 GMT  
 Problems using the $_POST[] array
"Dave Scott" wrote

Quote:
> Here is an excerpt from the code in question

But what did the simple readable sample code in my previous reply give
you?

a.



Mon, 23 May 2005 19:01:04 GMT  
 Problems using the $_POST[] array
It echoed whatever I typed in the name field correctly. Hmmm. I'll have to
take a closer look at my code then, eh? I must have missed something else.
Maybe I forgot a quote somewheres.

Thanks for all the help everyone,

Dave



Quote:
> "Dave Scott" wrote
> > Here is an excerpt from the code in question

> But what did the simple readable sample code in my previous reply give
> you?

> a.



Wed, 25 May 2005 21:37:03 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Problems using an array within another array

2. Undefined offsets on posted form using an array

3. convert 2d array to 1d array without using shift registers and build array

4. Problem with with Array of U8 to Array of Array of Boolean

5. Difficult problem to solve: Tcl 7.3 to Tcl 8.0p2 Array of Array Problem

6. Memory read problem when calling dynamic arrays in DLL built using VC++ (LabView 5)

7. Problem with defining *BIG* arrays using Verdix Ada on Apollo - Help Please

8. problem with reshape used with array pointers

9. problems with delivery of content of an array when using hyperreference

10. A problem about using array as subroutine argument in F77

11. Problem extracting array-indexed form data (using HTTP_POST_VARS)

12. problem using dynamic allocation of arrays in commons

 

 
Powered by phpBB® Forum Software