0

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

我有以下内容:

<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);
4

2 回答 2

0

您忘记关闭报价:

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

是这样吗?如果没有,请分享您遇到的任何错误。

于 2013-10-11T01:15:41.603 回答
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);
于 2013-10-11T01:16:24.240 回答