How to dynamically get form names in a PHP $Post

I am writing a page that takes a user's data from a database and displays it in a web page.  Then the user is given the option to update or delete portions of the information.  I am having an issue on the PHP side, after the user has submitted the form.  Here is an example of the form being submitted by the user.

<form action="submit.php" method="post">
     <input name="item4" type="text" />
     <input name="item75" type="text" />
</form>

Open in new window


Okay.  The important thing to note here is that the name for each text box is dynamically generated via php.  So it will never be the same.  It will always start out as "item", but the number is the ID number of the item stored in the database.  Also, the number of input items may be different.  Sometimes there may be 5 textboxes, other times there could be 20.

I am wondering if there is a way to a list of names that were posted without using a hidden field. Maybe something like $_Post[0].name(), where the zero is the first item in the post array, and the function name() would give me the name of the posted input.  

I don't know, as long as I don't have to write an entire novel's worth of code to get it to work would be good.  I am also new to php, so keep that in mind.
hendricksonHelpAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rik-LeggerCommented:
When you do something like this:

<input name="item[4]" type="text" />

Open in new window


Then you can in php retreive all the values like an array:

print_r($item);

Open in new window

hendricksonHelpAuthor Commented:
I thought about doing that, however, the issue comes in when I have 500 or 5000 entries in the entire database.  If it the first entry uses ID number 4000 and the last entry uses ID number 5000 I would have to loop through 1000 numbers to access each item individually...or would I?  Like I said, I am not familiar with php.
Rik-LeggerCommented:
No you don't,
you can do an foreach loop:

foreach ($_POST['item'] as $key => $value) {
   ...
}

Open in new window

OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

hendricksonHelpAuthor Commented:
Ok, so I will break this down, and you tell me if I am correct.
In "$_Post['item']" the item is the array.  If I had named the input as "Suzy[75]" then I would replace the post as "$_Post['Suzy']"

and the $key => $value....I have no idea what that is.  Does it change?  

Basically,I have a function called verify(str).

The verify function takes a string argument, and checks that string for illegal characters.  It returns false if no illegal characters were found, or true if there were illegal characters.

how would I use that function with this foreach statement?
Rik-LeggerCommented:
Your right with the naming thing, Suzy[75] will indeed become $_Post['Suzy'].

foreach ($_POST['item'] as $key => $value) {
   if (! verify($value)) {
       echo $key . ' contains illegal charaters . '<br />';
   }
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hendricksonHelpAuthor Commented:
I will test this later today, and award points.  Thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.