|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
PHP reading Javascript array problem
Hi,
I am populating an array in javascript and then POSTing this array to my PHP script. The problem is my PHP script doesnt seem to be able to find it! Im treating it as a regular PHP array in my PHP script, am I not taking something into account here? Hope you can help! Alba |
|
#2
|
|||
|
|||
|
Might this problem be related to register_globals = off?
Try accessing your array with $HTTP_POST_VARS["array"]. |
|
#3
|
|||
|
|||
|
Ive changed it from POST to GET.
The url of the recieving PHP script now shows this: mypage.php?name=fred&array=hey&array=you where "array" is my array. The number of elements im entering into it are determining the number of times "array=" is shown. This means it is being passed, how can i get at it, and is it actually an array?? Thanks btw CodeE |
|
#4
|
|||
|
|||
|
mypage.php?name=fred&array=hey&array=you
That isn't going to work. You are sending $array, which is set to "hey", and then you are sending $array which is set to "you". In the receiving script, $array will probably equal "you", I presume. It won't even be an array - it will just be a string with "you" in it. If I would be you, I would stick to using POST. Send the array as one variable. Do not try to send all the values in the array sepparately. That kinda destroys the point of an array, no? ![]() |
|
#5
|
|||
|
|||
|
I think ive found the problem, How do you pass an array to a PHP script? for example using hidden or another POST method?
|
|
#6
|
|||
|
|||
|
why don't you make your javascript code name the vars like they should:
array[1] array[2] or anything else. shouldnt be that hard, because normaly you have the counting var so it is easy to index your vars. if not possible try to change the name from array to array[] this will probably work better. |
|
#7
|
|||
|
|||
|
ive done that
I just need to know how to post an array to my PHP script. nothing seems to be working! ![]() |
|
#8
|
||||
|
||||
|
You should be able to access the POST array using the $_POST variables ($_POST['name'] == 'fred', and so on). If you're using an older version of PHP, you may need to use $HTTP_POST_VARS.
Please check PHP.net's description of reserved variables for more detail on what you're looking for.
__________________
Yawmark class Sig{public static void main(String...args){\u0066or(int \u0020$:"vÌÈÊ\"¤¾Àʲ¬Æ\"v¤Î¤\"²¤¨¸¬Æ".to\u0043h\u0061rArray() )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>> +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}} |
|
#9
|
|||
|
|||
|
i didnt think you could do such a thing in php. i thought you could only pass variable from input tags, and only pass an array from an select tag? right now, i have a similar problem but *solved* it by putting my javascript array contents into a hidden field, then sending that. if you can pass javascript variables, could someone post an example?
mrGarretson |
|
#10
|
||||
|
||||
|
it doesn't matter if the variable is created using javascript or declared directly in HTML code, every variable that is declared inside a FORM tag and then POSTed to the following page will be available in the $_POST array.
|
|
#11
|
||||
|
||||
|
Or he could push the array...
PHP Code:
|
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > PHP reading Javascript array problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|