Jump to content


Photo

Strange error with $_POST array


  • Please log in to reply
4 replies to this topic

#1 wh0mprat

wh0mprat
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 16 September 2006 - 11:58 PM

HI, everyone.

I don't seem to be able to access the keys in the $_POST associative array.

I have a script that dynamically generates a form. The form element
names are generated based on image filenames, so I can't just access
them the normal way in the form handler script. I tried looping through
the $_POST array like this:
foreach ($_POST as $key=>$value)
{

 echo $key.'=>'.$value.'<br>';
}
and i get this output:

0=>Pay
1=>Pay
2=>on
3=>on
4=>tn__DSC2602.jpg
5=>tn__DSC2603.jpg

Those numbers are where I expected to see the form element names. Can
anyond advise me on why this is happening?

Derek

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 17 September 2006 - 12:11 AM

Try echo $$key.'=>'.$value .....
Legend has it that reading the manual never killed anyone.
My site

#3 wh0mprat

wh0mprat
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 September 2006 - 12:15 AM

I tried that before, but with all I've been doing, I forgot about that, so I gave it another shot.

The result is that the number  (array index, I suppose) disappears and i have output like this:

=>Pay
=>Pay
=>on
=>on
=>tn__DSC2602.jpg
=>tn__DSC2603.jpg


#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 17 September 2006 - 01:45 AM

Do the following:
<?php
echo '<pre>' . print_r($_POST,true)  .'</pre>';
?>
What does the form look like?

Ken

#5 wh0mprat

wh0mprat
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 September 2006 - 04:32 PM

Well, the form is dynamically generated and looks like this right now

<FORM ACTION="ImageUpload3.php" METHOD="POST">
<INPUT type='checkbox' NAME='Include0' checked='true'>
<SELECT NAME='Tier0'>
	<option value='US'>US</option>
	<option value='EU' selected='selected'>Europe</option>
</SELECT>
<INPUT TYPE='INPUT' NAME='FileName0' VALUE='tn__DSC2795.jpg'>

<INPUT type='checkbox' NAME='Include1' checked='true'>
<SELECT NAME='Tier1'>
	<option value='US'>US</option>
	<option value='EU' selected='selected'>Europe</option>
</SELECT>
<INPUT TYPE='INPUT' NAME='FileName0' VALUE='tn__DSC2796.jpg'>
</FORM>

The form element names are placeholders for now, numbered by an iteration counter. I'll be giving them more meaningful names later.

When I tried Ken's suggestion, I got this:

Array
(
    [0] => EU
    [1] => EU
    [2] => on
    [3] => on
    [4] => tn__DSC2795.jpg
    [5] => tn__DSC2796.jpg
)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users