Solved

How to retrieve a dynamically created $_POST variable

Posted on 2009-07-06
7
168 Views
Last Modified: 2013-12-13
Hi all I need to retrieve a dynamically created field it should be named something like 0field, 1field, etc... It is created dynamically so I don't know how many fields are needed but I do know that they are created by using something like: $i."field", how should I go to retrieve it, since I cant seem to make it work no matter what I try?
The $i variable is a counter so I should be able to retrieve it inside a for as I'm trying but... No use...

A sample of code would be very appreciated...

Bellow is the code that I tried to make do, but ...

Thanks in advance to anyone who could crack it.
for($i=0;$i<$cont2;$i++){

$_SESSION['$x'] = $_POST['($i."field)"'];

}

Open in new window

0
Comment
Question by:doRodrigo
  • 3
  • 3
7 Comments
 
LVL 8

Accepted Solution

by:
lharrispv earned 500 total points
ID: 24785751
try this

 for($i=0;$i<$cont2;$i++){
$_SESSION['$x'] = $_POST[$i ."field"];
}
 
0
 

Author Closing Comment

by:doRodrigo
ID: 31600188
Thanks that was really it, even though I had tried it already, I probably had something misspelled. Congrats, thanks and here are the points...
0
 
LVL 11

Expert Comment

by:BrianMM
ID: 24785826
I suspect you need to make your for loop generate hidden inputs and pass them that way.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:doRodrigo
ID: 24786053
Actually no it the previous solution worked, I had misspelled something because I'm sure I had tried it already... Anyway thanks...
0
 
LVL 8

Expert Comment

by:lharrispv
ID: 24786427
Actually the problem was righ here...

The normal syntax for $_post is $_post["blah"].  The name of the field is in quotes because it is a string.    Also there are not prentices in it.

You had:
$_POST['($i."field)"'];
It contains prentices, and an extra single qutoe.  Basically you want it to wind up being the same as above.  $i . "field" is equivilent to strings such as 1field, 2field etc.

Does that make sense?

0
 

Author Comment

by:doRodrigo
ID: 24786552
Completely, I understood it from what you wrote, I had already tried it but had misspelled somewhat, but it was great the prompt feedback. Thanks again...
0
 
LVL 8

Expert Comment

by:lharrispv
ID: 24786648
no problem.  Glad I could help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now