d-lexy Posted September 18, 2007 Share Posted September 18, 2007 Hi All I have a big form with many fields. The form submits to a PHP file that updates a MySQL DB and also sends an email with some of the fields' values. Right now the PHP file that processes the data has a whole bunch of: $name = $_POST['name']; $phone = $_POST['phone']; $email = $_POST['email']; $message = $_POST['message']; etc... etc... I'm wondering if there is a way to replace these with some kind of array what would collect all those fields? Thanks in advance! -Alex Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 18, 2007 Share Posted September 18, 2007 $arr = $_POST; Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted September 18, 2007 Share Posted September 18, 2007 if you would prefer to create a new variable with the same name as each form element, you could use this: foreach($_POST AS $key=>$value) { ${$key} = $value; } Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 18, 2007 Share Posted September 18, 2007 Good one. Quote Link to comment Share on other sites More sharing options...
d-lexy Posted September 18, 2007 Author Share Posted September 18, 2007 if you would prefer to create a new variable with the same name as each form element, you could use this: foreach($_POST AS $key=>$value) { ${$key} = $value; } Yep, that one is much easier for me to understand than arrays Thanks to both of you! -Alex Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.