clay1 Posted January 9, 2010 Share Posted January 9, 2010 I've got a form I need to insert the values into my database I have some questions on the best way to get the variables out of the post array I found something online that said foreach (array_keys($_POST) as $key) { $$key = $_POST[$key]; That works except I have some multiple value options like check boxes which when I do a print on $key I just get 'array' What do I do here? Working on another site I had some issues with some serialized data becoming corrupted-- don't know if it was the fault of serialize and I should avoid it or if it was due to some other problem. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted January 9, 2010 Share Posted January 9, 2010 Check to see if the value is an array, if it is loop through that array, kinda like this: foreach (array_keys($_POST) as $key) { $key = $_POST[$key]; if(is_array($key)){ foreach($key as $k){ // do what you want for each checkbox } } } Quote Link to comment Share on other sites More sharing options...
clay1 Posted January 9, 2010 Author Share Posted January 9, 2010 Oh right, I forgot to include that in my post I had tried something similar. I got it working. I think if ($_POST) { foreach (array_keys($_POST) as $key) { $$key = $_POST[$key]; if (is_array(${$key})){ foreach(${$key} as $key2){ $$key2 = $_POST[$key2]; print "$key2 was part of array $key = $key<br />"; } } else{ print "$key is ${$key}<br />";} } } So now the best way to filter and check this stuff before putting it in my DB? Quote Link to comment Share on other sites More sharing options...
trq Posted January 9, 2010 Share Posted January 9, 2010 So now the best way to filter and check this stuff before putting it in my DB? There is no be-all-and-end-all method. Each element should be validated depending on the data expected. 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.