PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I've been pulling my hair out over this all afternoon, and it's driving me nuts. At work a few months ago, I was using a foreach loop that would grab all the post data from a form. After this foreach, I was able to access any post data from the form just using something like $form['username'];, where username is the name of an input field in the form. So if we wanted to input the username into a database, we'd just stick $form['username'] in the INSERT and it'd work a treat.
I've been trying to recreate this today, and have gotten no where. I'm starting to think it was some sort of black magic the guys had going on down at the office!
Anyone able to shed some light on this and stop me from going bald? Cheers.
There's no need to just transfer raw $_POST data into another array - that's a complete re-invention of the wheel. However, you should absolutely be massaging the data (as in, removing and adding slashes where necessary). In that case, you should store the massaged data in $form.
~JAM's code make's sense.
Your code doesn't because:
when you put $value in single quotes, PHP interprets it as the dollar sign followed by the string "value". You probably meant to put it in double quotes.
I think you're confused as to how foreach works. In every iteration of your foreach() loop, you're not setting anything, just declaring an array element. Use ~JAM's code.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.