PHP Form POST Question

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 SIGNED MESSAGE-----
Hash: SHA1

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/

iQIcBAEBAgAGBQJK15AjAAoJEF+XTK08PnB5gM8P/jPekpRhGPncX9i9qwzm7i9/
+AWTuYxclxA6vvFMNFOEr6+qglXP0GoS1VkAngTMxa6njo89mviYkK2O4DPz/00G
7HQyztoYvxIkt/7N1ghRezjPXOicKegIHQQDzasNxq0I2jUr7sPYXgaTAkcCrM4Q
yR84mhgvPFPLbM0MVS2ZNBc1cYHKGEqQJpxxxQnQ3rR7XNh+1RuCNaJbviVjAqgu
vITdw+oaChcib34MMboYEyNRSkBQG+Igpgys3BzJ1SMsCEwVPMb/yS7ZK8aLe926
8oByQiBGHN+2kIRE1BwghTFyuKRDfUHatlixN9m2VRsQv7Lf6l/aJeK+An5xpVMk
EbuW4QgRmZlbQcE/tEuNYRXLHh5OnwxT21Z3E5ZewGfssoUKC/JO07wdo8VHXSjZ
XnryzY0Vb0eCQ8Si1xvRzZZHCKyU0JW2Fr1vqzCjogCbpmZKKXKtBLxjsUayGG9D
wd8rSFbUIGcjbGy4ScGR6lCpvBkPfoeYH3p2EWO/FY3qK/vDmvSPwZ2VFUcc/wcT
HCfBWR/dtMCfVqJv4ho6g7mxp5aAaSI6wpou/MGzwu0pWGoIj9LHOoMjl1zjZ2FU
jFrBgCLfsHMLjsWuiNwQgySgZ1jxhdlzaCQtkoNoaI5DeO3pVUpeSXtcHUjqmvyy
UB0WiAOtsB4pRCrWDkfD
=JPYY
-----END PGP SIGNATURE-----

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 SIGNED MESSAGE-----
Hash: SHA1

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/

iQIcBAEBAgAGBQJK15vIAAoJEF+XTK08PnB5bS4QAI5YmvrLjTaEag7SEKgCQw50
T7kje0ixS5O6KehFoLEihkf81tyK+8BTYhzQOCEc+Rn2JMgm11HEiB2J5nquwwZd
3gK6n7PF843v3xUgwbxwTBGNOAYutOht5+sHzjmfJivKJS8Yov21z7h8ZATA6L7C
PAoPKm9M2NTY3P4HW/movxXYLB0FDVClMbQMRtWAEWrIh2LIn6NcNi4iiXwL76fD
zdjCNqyVT/14XiL42UgYoJk35ClRCiccWiypCFBLQIluhm41Fi9wq4brSaHe/4Of
yte70XIcs3rlljXuDcI9/SiquHOaUkCtGY/DPYQOgRcKSByEDCfZxPfErmhoLCNj
vtGeNaChV1FdeFjD0TtGCsXYiTrhMm4h3WtlKvslYIRRpGVlpoMyde/xiBi3gBQL
NE+ULNiG9TM1pVxdzekkTXTTWMs9hMNVeRyX2ebtbNkZNFwd+cT4mxA/dnQ6P5+4
noQqJS7LPV/xBzigzrRNJFd40+21+pE8hI5GkfZFmu9oLaKfZVSA45s0JR/b2w5a
xL/OQmehHlof0hv6OOEFaviIDqS3RK1p9YtQ/mpxtk+jfCZPe+TXeBIybEVqloUY
NbOs9+iwCeTerzhODhwe/mYi8u4pH15plvM3wMV//5kU10A7A81Hwp44+77tHbyN
fqtx5X/2f5REkivfHVdz
=dp/N
-----END PGP SIGNATURE-----

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
>
>
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:

foreach($_POST as $parm => $val)
{
$val = (string) $val;
$parm_string = “$parm=$val|”;
}