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
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.