Jump to content

Problem with POSTing a value in an array to a page.


Ragnos

Recommended Posts

This is my code on the page that I am POSTing to:

foreach($var1 as $var2)				{					include_once($var2['location']);				}

How do I POST a variable to this page so it gets included?I tried making a field in a form like this:

<input type="text" name="var1['location']" value="" />

but it doesn't work. What's the correct way to do this?

Link to comment
Share on other sites

The name attribute doesn't have to use apostrophes. I suppose it jus always sends it as a string. Use

<input type="text" name="var1[location]" value="" />

instead, OR make your PHP code expect the apostrophes like:

include_once($var2['\'location\'']);

Link to comment
Share on other sites

For some reason it still doesn't work. I tried the following to determine what goes wrong:

echo $var1;echo $var1['location'];echo $var2;echo $var2['location'];

The first three return the right value, but the last one only returns the first character of the value!Why is this? I can't change the PHP page anymore as I don't have access to it anymore, so how can I change my html code to make it work?Is it because I included it with $var2['location'] instead of $var2[location]?

Link to comment
Share on other sites

Well, I have register_globals ON (because I need it) so it should work. Why is it that the first three variables I echo (see my previous post) return the right value, but the last one only returns the first character? It's kinda weird.EDIT: I think I know what it is, but I don't know how to fix it :). the foreach() command takes each variable in the array $var1[], and then echo's it (in the test I did). However, it only echo's the value of the variable $var2['location'], so it expects an array inside the array $var1[], right?A correct value to submit would then be for example Sweden['location'], right? Then you get something like $var1[sweden['location']] or something.I'm a bit confused on what's the correct suntax though. I have tried submitting Sweden['location'], Sweden[location], and changing the name of the field to "var1[sweden[]]", but none of them work. Could someone help me with this last step?

Link to comment
Share on other sites

Why not just do

print_r($_POST);

and find your way to the variable you want?Again, if you ask me, you need the HTML<input type="text" name="var1[location]" value="" />and the PHP

include_once($var1['location']);

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...