Forum Moderators: coopster

Message Too Old, No Replies

POST problem

want to post an associated array

         

mcibor

10:37 pm on Feb 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all!

I've run into a problem - I would like to post an array that has association in it:
let me give you an example
<?php $names = array('coal', 'iron', 'brass');
echo '<form action="warehouse.php" name="warehouse" method="post">';
foreach($names as $name) {
echo '<input type="text" name="buy['.$name.']">';
echo '<input type="text" name="sell['.$name.']">';
}
echo '<input type="submit" name="action" value="Go">';
echo '</form>';

and what I would like to have is to receive two arrays:
$_POST['buy'] with "coal" => 2, "iron" => 4, "brass" => 0
and
$_POST['sell'] with "coal" => 0, "iron" => 0, "brass" => 8

However now on print_r($_POST) I get only Array ( [action] => Go )

Is that even possible?
I know that <input type="text" name="buy[]"> will work, but I loose then info about a material.

PS. inputs are db generated

Please provide any info.

Regards
Michal

dreamcatcher

10:54 pm on Feb 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Michal,

I just tested your code, entered some data and this is what I got:


Array
(
[buy] => Array
(
[coal] => 2
[iron] => 0
[brass] => 0
)

[sell] => Array
(
[coal] => 4
[iron] => 0
[brass] => 8
)

[action] => Go
)

So, the arrays should generate ok.

dc

mcibor

10:57 pm on Feb 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, I just spotted the mistake:
I wrote: <input type="buy[coal]"... and was surprised why it's not working :)

But thanks for your answer!

Have a good night