php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7934 HTTP_POST_VARS unable to handle same key multiple times
Submitted: 2000-11-22 17:03 UTC Modified: 2002-09-12 09:29 UTC
From: bzeeb+php at zabbadoz dot net Assigned:
Status: Closed Package: Variables related
PHP Version: 4.0.3 OS: FreeBSD
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bzeeb+php at zabbadoz dot net
New email:
PHP Version: OS:

 

 [2000-11-22 17:03 UTC] bzeeb+php at zabbadoz dot net
Using p.ex. function from FAQ 7.1 to read HTTP_POST_VARS one
is unable to handle/see all key-value-pairs when key is the same for
multiple values. I did not find any way to see all pairs (well one might define an array as name but that is not what CGI standard expects I think).

p.ex. having something like this in a HTML form:

<input type=checkbox name="FORM_key" value="2">
<input type=checkbox name="FORM_key" value="8">
<input type=checkbox name="FORM_key" value="19">

would only result in:

FORM_key -> 19
sizeof($HTTP_POST_VRS) = 1

instead of

FORM_key -> 2
FORM_key -> 8
FORM_key -> 19
where sizeof would return 3.

This is most likely caused by using some kind of associative array instead
of using indexes. I did not manage to solve this by using other array f()s.
I do not have time to look at the source code - sorry.
A simple dirty quick hack perl-script shows you that one does get all the
three values:

--- snipp ---
#!/usr/bin/perl

printf("Content-Type: text/html\n\n");

if ($ENV{'CONTENT_LENGTH'} > 0) {
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

    @pairs = split(/&/, $buffer);

    printf("\nPOST-Buffer (raw):<br>\n");
    printf("%s\n", $buffer);
    printf("\nPOST-Buffer (split up):<br>\n");

    foreach $pair (@pairs) {
            printf("%s<br>\n", $pair);
    }
} else {
        printf("NO HTTP_POST_VARs -> nothing to do here<br>\n");
}

# End;
--- snipp ---

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-11-23 05:25 UTC] sniper@php.net
Just add [] to the name. i.e. 

<input type="checkbox" name="FORM_key[]" value="2">

--Jani
 [2002-07-18 09:52 UTC] chrisrivera at chrisrivera dot com
Why is it that the '[]' is needed in the name attribute? Isn't this considered a bug then? Looping through the vars should return that it is an Array by default without the need of adding '[]' to the name attribute. This seems to be more of a hack than a solution.
 [2002-07-30 09:31 UTC] olivierdsm at hotmail dot com
This is what i codded :
<input type="checkbox" name="inmailtoupdate[]" value="<? echo $row['admins_id']; ?>">


then :
  $SQL = "update admins set admins_inmail='yes' where admins_id in ($inmailtoupdate)";

--> this is what i get as error message : "Unknown column 'Array' in 'where clause'


so, ok i can write something like echo inmailtoupdate[1], but how do i get the complette list???
 [2002-07-30 11:52 UTC] hholzgra@php.net
to chrisrivera@chrisrivera.com:

by giving the [] you specify that you *want*
an array while creating one auto-magicaly
whenever multiple values exists may confuse
form processing code as input variables may
be string or array depending on number of
selections made


to olivierdsm@hotmail.com:

this will do the trick for you:
"... IN (".join(",",$inmailtoupdate).") "
(but make sure $inmailtoupdate is not empty() before you do so)

please direct further questions to the php-general mailing list as we are no longer talking about bugs here

 [2002-09-05 16:59 UTC] dyonn at sympatico dot ca
Correct me if I'm wrong, but I actually think this is a bug because adding [] to the NAME of the checkbox makes the object to be unaccessible throught javascript(or really hard to access).

document.myform.mycheckbox[].lenght will give syntax error.

I browsed quite a lot on the net and I havent found the way to play with a JS variable named something[]
 [2002-09-05 17:25 UTC] rasmus@php.net
Every JS element has a numerical index number.  You do not have to use the name at all which allows you to call things whatever you want.
 [2002-09-12 08:22 UTC] m dot ford at lmu dot ac dot uk
Or you can use the feature of JavaScript that, *by* *definition*

    a.b

is identical to

    a['b']

so you could refer to

    document.myform['mycheckbox[]'].length
 [2002-09-12 09:29 UTC] bzeeb+php at zabbadoz dot net
please STOP this discussion here.
This bug-ID is _Closed_.

Either reopen or use a mailinglist...
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 13 09:01:27 2025 UTC