I have a script that loops through all POST variables with this type of loop:
foreach($_POST as $parm => $val)
{
$parm_string = “$parm=$val|”;
}
//more stuff here
The form that posts to this page has text boxes on it. If the user types “015” for one of the values in the text box, $val is automatically converted to 15 in the $parm_string variable.
Any suggestions to keep the “015” from the text box?
I am using:
php5-5.2.10-29.2
apache2-mod_php5-5.2.10-29.2
Wild guess… put quotes around $parm and $val on the foreach line.
Good luck.
pwright2 wrote:
> I have a script that loops through all POST variables with this type of
> loop:
>
> foreach($_POST as $parm => $val)
> {
> $parm_string = “$parm=$val|”;
> }
> //more stuff here
>
> The form that posts to this page has text boxes on it. If the user
> types “015” for one of the values in the text box, $val is automatically
> converted to 15 in the $parm_string variable.
>
> Any suggestions to keep the “015” from the text box?
>
> I am using:
> php5-5.2.10-29.2
> apache2-mod_php5-5.2.10-29.2
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
Doing
foreach($_POST as “$parm” => “$val”)
{
//code here
}
Results in a php error on the page. Is there another way I can loop through all $_POST variables? There are many forms that submit to this page and I need to parse each key/value pair of the $_POST array. I wonder if the foreach assignment is automatically converting $val to the datatype it believes will fit best.
Try viewing the output before you use your foreach and then alter afterward:
vardump($_POST) #or something like that… maybe var_dump)
Good luck.
pwright2 wrote:
> Doing
> foreach($_POST as “$parm” => “$val”)
> {
> //code here
> }
>
> Results in a php error on the page. Is there another way I can loop
> through all $_POST variables? There are many forms that submit to this
> page and I need to parse each key/value pair of the $_POST array. I
> wonder if the foreach assignment is automatically converting $val to the
> datatype it believes will fit best.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> I have a script that loops through all POST variables with this type of
> loop:
>
> foreach($_POST as $parm => $val)
> {
> $parm_string = “$parm=$val|”;
> }
> //more stuff here
>
> The form that posts to this page has text boxes on it. If the user
> types “015” for one of the values in the text box, $val is automatically
> converted to 15 in the $parm_string variable.
>
> Any suggestions to keep the “015” from the text box?
>
> I am using:
> php5-5.2.10-29.2
> apache2-mod_php5-5.2.10-29.2
>
>
Try
foreach($_POST as $parm => $val)
{
$parm_string = sprint(’%s=%s’, $parm, $val);
}
The var_dump($_POST) helped. It did show that it is a string in the array. For some reason, when it is in $val, it is converted to an integer. This seemed to work though: