php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34594 [Solved] Arrays from form get send over as string instead of array
Submitted: 2005-09-22 11:01 UTC Modified: 2005-09-22 15:12 UTC
From: thijs at toltech dot nl Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.0.5 OS: Gentoo Linux
Private report: No CVE-ID: None
 [2005-09-22 11:01 UTC] thijs at toltech dot nl
Description:
------------
By using form you can send Arrays over to the next page with the name="var_name[]" method.

However, doing this will result in that the $_POST['var_name'] will contain the string 'Array' all the time, no matter what is really send in.

(Note: this also happend to me in php5.1.0-b3, gentoo forced me to downgrade but I think it is also in php5.1.0-rc1, would be glad if anyone can check this for me)

Reproduce code:
---------------
<select name="color[]">
<option value="*">All</option>
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
<option value="orange">Orange</option>
<option value="yellow">Yellow</option>
</select>

and on the next page in php code:

<?php
print_r($_POST);
?>



Expected result:
----------------
The expected result is (assuming you selected 'Green' and 'Red':

Array 
(
    [color] = Array 
    (
        [0] = red
        [1] = green
    )
)

Actual result:
--------------
while will produce (no matter what you select):

Array 
(
    [color] = Array
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-22 11:11 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.0-win32-latest.zip

Works perfectly here.
 [2005-09-22 12:27 UTC] thijs at toltech dot nl
I'm unable to post feedback on this matter due to that make install fails on the location of the apache conf file. 

(Which is httpd.conf instead of apache2.conf, I configured php with the configuration taken from phpinfo() from my current php installation)
 [2005-09-22 12:31 UTC] sniper@php.net
Works fine for me too when using proper HTML form.

 [2005-09-22 12:50 UTC] thijs at toltech dot nl
I have been testing this now as well since  sniper@php.net sais this works.. it now works for me as well except in the form where I want it to work.. I first thought this was caused by the template engine, but it isn't..

I will try to find out what is causing this..
 [2005-09-22 15:07 UTC] thijs at toltech dot nl
Ok I found the problem, Every variable that is send over (GET and POST) variables is being checked:

foreach($_POST as $key => $value)
    $_POST[$key] = addslashes(trim($value));

This somehow caused it to be a string with the value 'Array'. I searched around for help and found one similair bug on this site that was exactly the same.. so I thought it was a php bug.

Sorry for this invalid bug post..
I closed it now
 [2005-09-22 15:12 UTC] tony2001@php.net
We mark user errors as 'Bogus'.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 26 19:01:30 2024 UTC