openSUSE Forums > Programming/Scripting » PHP Form POST Question

Go Back   openSUSE Forums > Programming/Scripting
Forums FAQ Members List Search Today's Posts Mark Forums Read


Programming/Scripting Questions about programming, bash scripts, perl, php, cron jobs, ruby, python, etc.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 15-Oct-2009, 15:58
Puzzled Penguin
 
Join Date: Mar 2009
Posts: 28
pwright2 hasn't been rated much yet
Default 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
Reply With Quote
  #2 (permalink)  
Old 15-Oct-2009, 16:12
Explorer Penguin
 
Join Date: Apr 2009
Posts: 690
ab@novell.com hasn't been rated much yet
Default Re: PHP Form POST Question

-----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+qglXP0GoS1VkAngTMxa6njo89mv iYkK2O4DPz/00G
7HQyztoYvxIkt/7N1ghRezjPXOicKegIHQQDzasNxq0I2jUr7sPYXgaTAkcCrM4Q
yR84mhgvPFPLbM0MVS2ZNBc1cYHKGEqQJpxxxQnQ3rR7XNh+1R uCNaJbviVjAqgu
vITdw+oaChcib34MMboYEyNRSkBQG+Igpgys3BzJ1SMsCEwVPM b/yS7ZK8aLe926
8oByQiBGHN+2kIRE1BwghTFyuKRDfUHatlixN9m2VRsQv7Lf6l/aJeK+An5xpVMk
EbuW4QgRmZlbQcE/tEuNYRXLHh5OnwxT21Z3E5ZewGfssoUKC/JO07wdo8VHXSjZ
XnryzY0Vb0eCQ8Si1xvRzZZHCKyU0JW2Fr1vqzCjogCbpmZKKX KtBLxjsUayGG9D
wd8rSFbUIGcjbGy4ScGR6lCpvBkPfoeYH3p2EWO/FY3qK/vDmvSPwZ2VFUcc/wcT
HCfBWR/dtMCfVqJv4ho6g7mxp5aAaSI6wpou/MGzwu0pWGoIj9LHOoMjl1zjZ2FU
jFrBgCLfsHMLjsWuiNwQgySgZ1jxhdlzaCQtkoNoaI5DeO3pVU peSXtcHUjqmvyy
UB0WiAOtsB4pRCrWDkfD
=JPYY
-----END PGP SIGNATURE-----
Reply With Quote
  #3 (permalink)  
Old 15-Oct-2009, 16:28
Puzzled Penguin
 
Join Date: Mar 2009
Posts: 28
pwright2 hasn't been rated much yet
Default Re: PHP Form POST Question

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.
Reply With Quote
  #4 (permalink)  
Old 15-Oct-2009, 17:01
Explorer Penguin
 
Join Date: Apr 2009
Posts: 690
ab@novell.com hasn't been rated much yet
Default Re: PHP Form POST Question

-----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+XTK08PnB5bS4QAI5YmvrLjT aEag7SEKgCQw50
T7kje0ixS5O6KehFoLEihkf81tyK+8BTYhzQOCEc+Rn2JMgm11 HEiB2J5nquwwZd
3gK6n7PF843v3xUgwbxwTBGNOAYutOht5+sHzjmfJivKJS8Yov 21z7h8ZATA6L7C
PAoPKm9M2NTY3P4HW/movxXYLB0FDVClMbQMRtWAEWrIh2LIn6NcNi4iiXwL76fD
zdjCNqyVT/14XiL42UgYoJk35ClRCiccWiypCFBLQIluhm41Fi9wq4brSaHe/4Of
yte70XIcs3rlljXuDcI9/SiquHOaUkCtGY/DPYQOgRcKSByEDCfZxPfErmhoLCNj
vtGeNaChV1FdeFjD0TtGCsXYiTrhMm4h3WtlKvslYIRRpGVlpo Myde/xiBi3gBQL
NE+ULNiG9TM1pVxdzekkTXTTWMs9hMNVeRyX2ebtbNkZNFwd+c T4mxA/dnQ6P5+4
noQqJS7LPV/xBzigzrRNJFd40+21+pE8hI5GkfZFmu9oLaKfZVSA45s0JR/b2w5a
xL/OQmehHlof0hv6OOEFaviIDqS3RK1p9YtQ/mpxtk+jfCZPe+TXeBIybEVqloUY
NbOs9+iwCeTerzhODhwe/mYi8u4pH15plvM3wMV//5kU10A7A81Hwp44+77tHbyN
fqtx5X/2f5REkivfHVdz
=dp/N
-----END PGP SIGNATURE-----
Reply With Quote
  #5 (permalink)  
Old 16-Oct-2009, 07:52
Student Penguin
 
Join Date: Jun 2008
Location: Norwich, UK
Posts: 78
fudokai hasn't been rated much yet
Default Re: PHP Form POST Question

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);
}

Reply With Quote
  #6 (permalink)  
Old 16-Oct-2009, 15:26
Puzzled Penguin
 
Join Date: Mar 2009
Posts: 28
pwright2 hasn't been rated much yet
Default Re: PHP Form POST Question

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|";
}
Reply With Quote
Reply

Bookmarks


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2