473,544 Members | 2,231 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ]
[ su*******@12jab ber.com <--jabber IM ]
Jul 17 '05 #1
4 17212
Sugapablo <ru********@sug apablo.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
Jul 17 '05 #2
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 =--
Jul 17 '05 #3
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.
Jul 17 '05 #4
In article <Xn************ **************@ 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 ]
[ su*******@12jab ber.com <--jabber IM ]
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
13567
by: NotGiven | last post by:
I am looking for a standard way/function to loop through all POST variables and their respective contents to update a database record. Here's my ideal to pass a function and it update: session variable - "ID" - that holds the record ID to update $_POST or $HTTP_POST_VARS The function would update the $_POST vaiables of the ID record with...
3
50250
by: Joe This | last post by:
Is there a way to loop through all GET and POST Variables? For instance; if I send 3 Get variables, but I do not want to know the names of each variable. I want to loop through and echo the name of the variable and the value.
13
1802
by: Marcus | last post by:
Hi All, I was wondering if there is a way to ensure that when submitting forms and using POST vars, the page sending the form resides on the same server as the destination page specified in the form action. For example, if I have a page on a live server that accepts POST variables, I can simply create a second page on my local host or any...
1
3026
by: sarah | last post by:
Hi.. I'm having a problem trying to figure out the best way to process a POST and add items to my database, and hope someone can help me... :) Background: I have a database that I will use to hold Purchases of Items Each Item purchased is stored in it's own record: ....etc...
5
5332
by: Kit | last post by:
Hi there, I am recoding a website, and I want to add a generic footer to each page, using an included file with PHP snippets. Part of that footer would be a link to validate the page using the W3C's validation service. The code currently looks like this: <code> <a href="http://validator.w3.org/check?uri=<?php echo...
2
4698
by: Deb M. | last post by:
I am trying to find out how I can use the ASP.net framework yet still post the variables to an external script (not ASPX) after the form has been submitted. So, the ASPX page will still post to itself, but then I need to transfer the variables to another page. I need to do this transfer using the POST method and not the GET method. I...
3
1819
by: Lars Netzel | last post by:
Hello! I have a button, in the click event I have this code: ---------------------------------------------------------------------------- ---------------------------- Response.Write("<script language=javascript>window.open('CrystalReports.aspx?FromDate=" & txtFromDate.Text & "&ToDate=" & txtToDate.Text & "&File=" &...
3
2059
by: Vic Spainhower | last post by:
Hello, I have an HTML table that is being constructed from a MySQL table and displays a form that includes a check box on 1 of the fields on the form for each record. I have included in this PHP program a javascript routine called sorttable.js which is something I found on the internet for sorting tables and works quite well. The HTML...
2
8097
by: Aaron | last post by:
I'm trying to pull data from a website and read it into a file the I can parse. I've done the before to site without post variables but I can seem to get my statments to work with the post. Can someone help me out? below is the code I have so far. Thank in advance... $url="www.somesitethatneedspostvariables.com"; $postdata =...
4
5212
by: SupraFast | last post by:
I have 2 forms on one page. I have hidden variables in each form, with separate names, that contain values. The user decides which form to submit on. Only 1 form will be processed. Now my problem is, when I read the Post Variables from the server side with PHP. foreach($_POST as $name => $value) { print "$name : $value<br>"; }
0
7783
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7720
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5931
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5309
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3430
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3422
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1850
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
996
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
677
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.