Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving data from 2D Array's off of Form Submits

Status
Not open for further replies.

justride

Programmer
Jan 9, 2004
251
US
The following code was working, not sure the version of PHP that I was using, but I know it worked on 4. Rrecently my host upgraded to PHP Version 5.2.13, and all of the code is broken.

I have an HTML Form Submit.

My HTML Form POST the following variable "requirements" as 2D array data fine, which I can see in the HTTP POST via HTTPAnalyzer.

Here is the data from the POST
Code:
requirements[0][] = 1
requirements[0][] = 2
requirements[0][] = 3
                                                
requirements[1][] = 4
requirements[1][] = 5
requirements[1][] = 6

In PHP I am doing the following which no longer seems to work.

Code:
$requirements[][] = $_POST['requirements[][]'];
$_SESSION['requirements'] = $requirements;

...

for($i=0;$i<=$requirementArrayCount;$i++)
{
    $requirementsDelimited = '';
    for($x=$i;$x<$i+1;$x++)
    {
        for($j=0;$j<count($requirements[$x]);$j++)
        {
	    $requirementsDelimited = $requirementsDelimited.";".trim($requirements[$x][$j]);
	}
    }
    // do something with requirementsDelimited
}

Usually, requirementsDelimted would be "1;2;3" and "4;5;6"

Now what is happening is only 1 iteration is happening for each loop, and requirements[0] is an array of length 1 with no value at requirements[0][0]

Thoughts? Workarounds?

I'm not saying the code is pretty, but this has been in place for 5 years and stopped working just recently.

Thanks,
Chris
 
There is no obvious reason why your code will have broken between php 4 and php5.
Code:
session_start();
$_SESSION['requirements'] = $_POST['requirements'];
$requirementsDelimited = array();
foreach($_POST['requirements'] as $val):
 $requirementsDelimited[] = implode (';', $val);
endforeach;
print_r($requirementsDelimited);

 
I will try your much cleaner implementation this evening.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top