Re: Post-Vars doubled / corrupted
| From: | Aaron Koning | Date: | Fri, 16 Dec 2005 03:58:37 +0000 |
| Subject: | Re: Post-Vars doubled / corrupted | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-227511@lists.php.net to get a copy of this message | ||
Hi Sabine,
Its been my experience that you need square brackets after the input
checkbox name for PHP to see an array. This page discusses that:
http://www.evolt.org/article/Storing_form_array_data_to_MySQL_using_PHP/18/60222/
Change your code to the following and give it a try.
<ul id="colors">
<li><input name="colors[]" id="id1" type="checkbox"
value="1"
/><label for="id1">red</label></li>
<li><input name="colors[]" id="id2" type="checkbox"
value="2"
/><label for="id2">blue</label></li>
</ul>
Aaron
On 12/15/05, Sabine <phpdev@sric.de> wrote:
>
> Hi Aaron,
> thanks for your answer. The HTML elements, which "represent" arrays are
> causing problems.
> I just added
> <ul id="colors">
> <li><input name="colors" id="id1"
> type="checkbox" value="1"
> /><label for="id1">red</label></li>
> <li><input name="colors" id="id2"
> type="checkbox" value="2"
> /><label for="id2">blue</label></li>
> </ul>
>
> to your minimalistic script.
> Checked both and got
> Array ( [colors] => Array ( [0] => 1 [1] => 2 [2] => 2 ) [testvar] =>
> pleasedontcorrupt [submit] => submit )
> for post.
>
> I don't really think it's a problem of my code.
> Perhaps a problem of the servers configuration. But I'm not really
> familiar with installation and configuration duties. So I don't know
> where to search.
>
> But meanwhile I read something about input filters in Apache 2.
> And thought if there is a filter on this server which corruptes my post
> vars?
>
> Config is (I don't know which parameters are really importend):
> ["IHOST_VERSION"]=> "Linux-1.0"
> ["SERVER_SOFTWARE"]=> "Apache/2.0.55
> ["SERVER_PROTOCOL"]=> "HTTP/1.1"
>
> PHP 4.3.11
> Server API Apache 2.0 Filter
>
> I searched for information if PHP 4.3.11 is supposed to work fine with
> Apache 2.0.55, but didn't find a clear answer.
>
> Perhaps you know (or someone else knows) if my thoughts are going in the
> right direction?
>
> Bye
> Sabine
>
>
>
>
>
>
>
>
>
>
>
>
> Aaron Koning schrieb:
>
> > I wasn't aware you could use = instead of echo (<?
> > =$_SERVER['PHP_SELF'] ?>). Try making an even simpler HTML/PHP example
> > and see if the problem exists there. Then you can incrementally build
> > your HTML/PHP back up to the point where it is breaking. Example:
> >
> > <?php
> > print_r($_POST);
> > ?>
> > <html>
> > <head>
> > </head>
> > <body>
> > <form action="" method="post">
> > <input type="hidden" name="testvar"
> > value="pleasedontcorrupt" />
> > <input type="submit" name="submit" value="Submit"
> > />
> > </form>
> > </body>
> >
> >
> > Aaron
> >
> > On 12/15/05, *Sabine* <phpdev@sric.de <mailto:phpdev@sric.de9p
> > *ÄÜÑ‚÷fÖ"ùE>> wrote:
> >
> > Hello to all,
> >
> > I distributed my app to a new server and suddenly had values saved
> > twice
> > in the db and so on.
> > I tracked it down and found out, that the problem is the content
> > of $_POST.
> > Vars are doubled, Strings corrupted. Absolutely absurd.
> > I have no idea where to search for the reasons.
> > PHP-Version is 4.3.11
> > Does anybody else have an idea?
> >
> > Thank you in advance
> > Sabine
> >
> >
> > A simple testcase:
> >
> > <?php
> > echo "Post:";
> > var_dump($_POST);
> > ?>
> > <html>
> > <body >
> > <form id="formular"
> > action="<?=$_SERVER['PHP_SELF'] ?>"
> > method="post">
> >
> > <ul id="colors">
> > <li><input class="buttons" name="colors[]"
> > id="id1"
> > type="checkbox" value="1" title="chose color"
> > /><label
> > for="id1">red</label></li>
> > <li><input class="buttons" name="colors[]"
> > id="id2"
> > type="checkbox" value="2" title="chose color"
> > /><label
> > for="id2">blue</label></li>
> >
> > <li><input class="buttons" name="colors[]"
> > id="id3"
> > type="checkbox" value="3" title="chose color"
> > /><label
> > for="id3">green</label></li>
> > <li><input class="buttons" name="colors[]"
> > id="id4"
> > type="checkbox" value="4" title="chose color"
> > /><label
> > for="id4">yellow</label></li>
> > </ul>
> >
> > <fieldset class="nolegend">
> > <input type="submit" value="change colors"
> > name="aendern" />
> > <input type="submit" value="save colors"
> > name="speichern" />
> > </fieldset>
> > </form>
> > </body>
> > </html>
> >
> > Output for $_POST, if you just click on "change colors":
> > Post: array(1) { ["aendern"]=> string(34) "change
> colorsaendern=change
> > colors" }
> >
> >
> > Output, if you check only "red" and click "change colors":
> > Post: array(2) { ["colors"]=> array(1) { [0]=> string(1) "1"
> > }
> > ["aendern"]=> string(13) "change colors" }
> >
> > output for 2 colors checked:
> > Post: array(2) { ["colors"]=> array(3) { [0]=> string(1) "1"
> > [1]=>
> > string(1) "2" [2]=> string(1) "2" } ["aendern"]=>
> > string(13) "change
> > colors" }
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>