posting multiple select items to mysql
Posted: Fri Aug 19, 2011 10:08 am
Good Afternoon,
I have the following code here
form.php (a snippet of it)
submitrecipe.php
The drop down list in contributor gets the list from another table within the database, but when I try and post multiple selections, I get just the last item clickedsent across. Im not sure what needs to be changed to allow this to work for this form menu item
I have the following code here
form.php (a snippet of it)
Code: Select all
<form action="recipesubmit.php" method="post">
<br>
Course
<select name="ccourse">
<?php
$sql1 = "SELECT course FROM ccourse ".
"ORDER BY course";
$rs1 = mysql_query($sql1);
while($row1 = mysql_fetch_array($rs1))
{
echo "<option value=\"".$row1['course']."\">".$row1['course']."</option>\n ";
}
?>
</select><br><br>
Contributor
<select name="contributor" multiple>
<?php
$sql1 = "SELECT contributor FROM contributor ".
"ORDER BY contributor";
$rs1 = mysql_query($sql1);
while($row1 = mysql_fetch_array($rs1))
{
echo "<option value=\"".$row1['contributor']."\">".$row1['contributor']."</option>\n ";
}
?>
</select><br><br>
submitrecipe.php
Code: Select all
<?php
include 'connect.php';
$title = $_POST['title'];
$contributor = $_POST['contributor'];
$client = $_POST['corporate'];
$fcourse = $_POST['fcourse'];
$ftype = $_POST['ftype'];
$book = $_POST['book'];
$ccourse = $_POST['ccourse'];
$code = $_POST['code'];
$program = $_POST['program'];
$series = $_POST['series'];
$day = $_POST['day'];
$week = $_POST['week'];
$year = $_POST['year'];
$image= $_POST['image'];
$link= $_POST['link'];
if(!$_POST['submit']) {
echo 'please fill out the form';
header('Location: index1.php');
} else {
mysql_query("INSERT INTO Recipes (`id`,`Title`,`Contributor`,`Course`,`Client`,`Year`,`Series`,`Week`,`Code`,`Day`,`Foodcourse`,`Foodcategory`,`Prog`,`Book`,`image`,`Links`)
VALUES(NULL,'$title','$contributor','$ccourse','$client','$year','$series','$week','$code','$day','$fcourse','$ftype','$program','$book','$image','$link')") or die(mysql_error());
echo "New Recipe Added";
header('Location: index1.php');
}
?>