Jump to content

$_POST array and serialize?


clay1

Recommended Posts

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/187795-_post-array-and-serialize/
Share on other sites

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.