I’ve got a couple of times in one form that I serialize an array to store as one variable in the mysql database. Two of the four are not working right. I’m getting this error:
Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/.nelya/amosglenn/amosglenn.com/campaign/contactform.php on line 71
What I’m doing is to check the array to see if the user has signed up for a specific day (there is a group of checkboxes that go into the array.
It looks like the array is being stored correctly (at least it looks like a serialized array, that is, a bunch of letters numbers and punctuation). But the form seems to think that I’m not getting an array back when I unserialize the value from the database.
Here is the code that unserializes the variable retrieved from the database:
<table cellpadding='6'>
<tr class='grouplabel'><td colspan='2'>Discussion Group Information</td></tr>
<tr><td colspan='2'>
<table cellpadding='6'>
<?php
$cdd=array();
$cdd = unserialize($cdiscussionday);
$cdt=array();
$cdt=unserialize($cdiscussiontime);
?>
<tr><td>The best days for me to meet with a group is:</td></td>
<tr><td><input type="checkbox" name="discussionday[]" value="sunday"
<?php if(in_array("sunday",$cdd)) {print('CHECKED');} ?>
>Sunday
<!-- the rest of the days are identical, snipped here for readability -->
</td></tr>
</table>
And here is the code that serializes the information for starage:
[code] isset($_POST[‘discussionday’]) ? $cdiscussionday = serialize($_POST[‘discussionday’]) : $cdiscussionday="";
isset($_POST['discussiontime']) ? $cdiscussiontime = serialize($_POST['discussiontime']) : $cdiscussiontime="";
[/code]
I’ve read everything on serialization I can find, but this is driving me crazy.
Thanks for any help!