将多个选择下拉列表保存到1列中

时间:2013-10-11 01:10:14

标签: php mysql sql html-select

我想将多个下拉选项保存到数据库中的一列中。

我有以下内容:

<select name="pack_choice[]" style="width:270px; margin-bottom:2px;">
<option value=''>---Select---</option>
<?php 
$query = mysql_query("SELECT * FROM tbl_package_source where pack_type = 'Bronze' AND pack_desc = 'Pasta/Noodles/Vegetables'");
while ($row = mysql_fetch_array($query)){
$pack_id = $row['pack_code'];
echo "<option value='".$row['pack_code']."'>".$row['pack_part']."</option>";
} ?>
</select>
<select name="pack_choice[]" style="width:270px; margin-bottom:2px;">
<option value=''>---Select---</option>
<?php 
$query1 = mysql_query("SELECT * FROM tbl_package_source where pack_type = 'Bronze' AND pack_desc = 'Seafoods'");
while ($row = mysql_fetch_array($query1)){
$pack_id = $row['pack_code'];
echo "<option value='".$row['pack_code']."'>".$row['pack_part']."</option>";
}
?>
</select><br/>

这是我的查询

$pack_choice = implode(", ",$_POST['pack_choice']);
$qry = "Insert INTO tbl_packages (pack_choice) VALUES ('{$pack_choice}')";
$result_set = mysql_query($qry);

2 个答案:

答案 0 :(得分:0)

你忘了关闭引用:

$qry = "Insert INTO tbl_packages (pack_choice) VALUES ('{$pack_choice}')";

是这样的吗? 如果不是,请分享您得到的任何错误。

答案 1 :(得分:0)

$pack_choice = implode(", ",$_POST['pack_choice']);
print_r($pack_choice); // HAVE YOU TRIED TO PRINT OUT //
$qry = "Insert INTO tbl_packages (pack_choice) VALUES ('{$pack_choice}');
$result_set = mysql_query($qry);