Help with $_POST variables. Reading their names.

This is a discussion on Help with $_POST variables. Reading their names. within the PHP Language forums, part of the PHP Programming Forums category; I have a dynamic form that that creates input variables named different things based on what it reads from the ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-26-2003
Sugapablo
 
Posts: n/a
Default Help with $_POST variables. Reading their names.

I have a dynamic form that that creates input variables named different
things based on what it reads from the database.

So, for example, it may create three fields, named ex12, ex23, and ex45
respectively, and send those fields and their values via POST to a PHP
page.

So these would be sent basically:
$_POST['ex12'] which may equal "cow".
$_POST['ex23'] which may equal "cat".
$_POST['ex45'] which may equal "dog".

Now, I can easily count how many variables are sent using count($_POST)
and know that 3 variables were sent. The question is, how to I
determine what the names of the variables are? How do I determine if
sent were ex12, ex23, and ex45 as opposed to ex4, ex25, and ex65?


--
[ Sugapablo ]
[ http://www.sugapablo.com <--music ]
[ http://www.sugapablo.net <--personal ]
[ sugapablo@12jabber.com <--jabber IM ]
Reply With Quote
  #2 (permalink)  
Old 11-26-2003
Jon Kraft
 
Posts: n/a
Default Re: Help with $_POST variables. Reading their names.

Sugapablo <russREMOVE@sugapablo.com> wrote:

> I have a dynamic form that that creates input variables named
> different things based on what it reads from the database.
>
> So, for example, it may create three fields, named ex12, ex23, and
> ex45 respectively, and send those fields and their values via POST to
> a PHP page.
>
> So these would be sent basically:
> $_POST['ex12'] which may equal "cow".
> $_POST['ex23'] which may equal "cat".
> $_POST['ex45'] which may equal "dog".
>
> Now, I can easily count how many variables are sent using
> count($_POST) and know that 3 variables were sent. The question is,
> how to I determine what the names of the variables are? How do I
> determine if sent were ex12, ex23, and ex45 as opposed to ex4, ex25,
> and ex65?


foreach($_POST as $key => $value){
echo $key.": ".$value;
}

HTH;
JOn
Reply With Quote
  #3 (permalink)  
Old 11-26-2003
Pedro Graca
 
Posts: n/a
Default Re: Help with $_POST variables. Reading their names.

Sugapablo wrote:
> I have a dynamic form that that creates input variables named different
> things based on what it reads from the database.
>
> So, for example, it may create three fields, named ex12, ex23, and ex45
> respectively, and send those fields and their values via POST to a PHP
> page.
>
> So these would be sent basically:
> $_POST['ex12'] which may equal "cow".
> $_POST['ex23'] which may equal "cat".
> $_POST['ex45'] which may equal "dog".
>
> Now, I can easily count how many variables are sent using count($_POST)
> and know that 3 variables were sent. The question is, how to I
> determine what the names of the variables are? How do I determine if
> sent were ex12, ex23, and ex45 as opposed to ex4, ex25, and ex65?


First thing that comes to mind is:

<?php
foreach ($_POST as $k=>$v) {
// $k is 'ex12', 'ex23', ...
// $v is 'cow', 'dog', ...
}
?>

HTH
--
--= my mail address only accepts =--
--= Content-Type: text/plain =--
Reply With Quote
  #4 (permalink)  
Old 11-26-2003
Christian Debt Man
 
Posts: n/a
Default Re: Help with $_POST variables. Reading their names.

Sugapablo, doing a poor impression of Quincy, said:
>
> determine what the names of the variables are? How do I determine if
> sent were ex12, ex23, and ex45 as opposed to ex4, ex25, and ex65?


one way would be to use a foreach loop:

foreach($_POST as $key => $value)
echo "variable $key had value $value\n";

/joe
--
E. Robert Frank asks for help from Bwooce and Uncle Heinie Way. Jess does
an impression of Kurt Eiselt for a router? The Knights of Parking cleverly
punches Matt Labbe's desktop from Uni.
Reply With Quote
  #5 (permalink)  
Old 11-26-2003
Sugapablo
 
Posts: n/a
Default Re: Help with $_POST variables. Reading their names.

In article <Xns943FB35A7FAD7jonjonuxcouk@130.133.1.4>, Jon Kraft wrote:
>
> foreach($_POST as $key => $value){
> echo $key.": ".$value;
> }


Thank you (to each who answered). :)

--
[ Sugapablo ]
[ http://www.sugapablo.com <--music ]
[ http://www.sugapablo.net <--personal ]
[ sugapablo@12jabber.com <--jabber IM ]
Reply With Quote
Reply


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

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



All times are GMT +1. The time now is 11:40 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0