How to retrieve a dynamically created $_POST variable

Posted on 2009-07-06
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.
$_SESSION['$x'] = $_POST['($i."field)"'];

Open in new window

Question by:doRodrigo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3

Accepted Solution

lharrispv earned 500 total points
ID: 24785751
try this

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

Author Closing Comment

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...
LVL 11

Expert Comment

ID: 24785826
I suspect you need to make your for loop generate hidden inputs and pass them that way.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

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

Expert Comment

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


Author Comment

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

Expert Comment

ID: 24786648
no problem.  Glad I could help.

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

718 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