0

Today I came across the strange behaviour with PHP _POST array. When submitting form fields named as multidimensional array PHP supports, the POST is filled with only the first value from array. Found this on PHP 5.3.8 (SLES 11 SP2). The same code works normally on all other systems I have access to including PHP 5.2, 5.3.18, and 5.4. Here is a test case:

<form method="POST" action="test.php">
<input type="text" name="single" value="sss"/><br>
<input type="text" name="multi[a]" value="AAA"/><br>
<input type="text" name="multi[b]" value="BBB"/><br>
<input type="text" name="single2" value="CCC"/><br>
<input type="submit">
</form>
<?php
$raw_post = file_get_contents('php://input');
print $raw_post;
phpinfo(INFO_VARIABLES);

After submitting this I get the following in raw data:

single=sss&multi%5Ba%5D=AAA&multi%5Bb%5D=BBB&single2=CCC

But $_POST array is filled only with first value from "multi", $_POST['multi'] provides:

Array
(
    [a] => AAA
)

Does anybody know why this can happen?

5
  • 1
    does this happen often when you test this code? I tried your code and it seems to var_dump($_POST['multi']) correctly. It shows an array containing 'a' and 'b' Commented Mar 17, 2016 at 14:15
  • The result is the same every time :( Stuck with this issue for two days, can't imagine why this happens ... Commented Mar 17, 2016 at 14:40
  • I modified the printing of your code a little here: preview.c9users.io/reneecampanilla/sof-36062907 and you can test it here: sof-36062907-reneecampanilla.c9users.io Commented Mar 17, 2016 at 15:00
  • Thanks Ren, I see its working on your server. It also works on my other servers but not on 5.3.8. I found another user complained about the same issue and his solution was to update PHP. stackoverflow.com/questions/12684449/… Commented Mar 17, 2016 at 15:58
  • Upgrading/updating is a good idea. Good luck with your programming! Commented Mar 17, 2016 at 23:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.