I'm having trouble submitting checkboxes to a sql database. I have two tables, one contains user information - name, email address, password, and the other contains the information they select through the checkboxes. I'm not sure whether to have multiple columns - one for uid, which will match the users original id, and the rest for each checkbox with a bool type, and to submit yes or no as to whether the box was checked, or whether to just have two columns, one in which the value of each checked checkbox is submitted. And if I do it this way, what type should the second column be? A varchar? Because that doesn't hold that many characters.
Right now, the XHTML for the webpage looks like this:
<td><input type = "checkbox" name="food[]" value="Steak">Steak
</td>
</tr>
<tr>
<td><input type="checkbox" name = "food[]" value="French Fries"> French Fries</td>
Should I be doing something like this?
<?
if(isset($_POST['food']))
{
$food = implode(',', $_POST['food']);
$insertquery = sprintf("INSERT INTO test (uid, food) VALUES ('%d',
'%s')", $_SESSION["uid"], $food);
$result = mysql_query($insertquery);
?>
I'm pretty confused so please help! Or if this is pretty basic, if you could redirect me to a tutorial that addresses this issue, I've had trouble finding one that goes into checkboxes.
Thanks!