I'm new to PHP/SQL so help please
I'm trying to create a form that will allow users to select certain foods, using checkboxes, and then submit that information to the table in mysql.
<form action = "choice2.php" method = "post">
<table border = "0">
<tr>
<td><input type = "checkbox" name= food[] value="Chicken
Parmesean">Chicken Parmesean
</td>
</tr>
<tr>
<td><input type="checkbox" name = food[] value="Fried Plantains"> Fried Plantains</td>
</tr>
</form>
<?
$food = $_POST['food']
$query = sprintf("INSERT INTO foods (uid, food) VALUES ('%d', '%s')", $_SESSION["uid"],
$food);
$result = mysql_query($query);
?>
i've been trying a number of different ways, first without using an array, but with each option as a separate variable, but i can't seem to get anything to work. any suggestions?
can't get that suggestion to work - see below
<form action = "choice2.php" method = "post">
<td class="field">Chicken Parmesean</td>
<td><input name = "chicken_parmesean" type="checkbox" value
= "Chicken Parmesean"/></td>
<tr>
<td class="field">Fried Plantains</td>
<td><input name = "fried_plantains" type ="checkbox" value =
"Fried Plantains"/></td>
</form>
<?
$chicken_parmesean = $_POST['chicken_parmesean']
$fried_plantains = $_POST['fried_plantains']
//prepare SQL - should insert true if checked, false if unchecked
$query = sprintf("INSERT INTO foods (uid, Chicken Parmesean, Fried
Plantains) VALUES ('%d', '%s', '%s')", $_SESSION["uid"],
$chicken_parmesean, $fried_plantains);
$result = mysql_query($query);
in the table i have a row for each different food, set as a bool, though i've also tried it as a string or text. 0 always is submitted