我试图从表单帖子添加多个值到我的SQL表(program_celebrity),我在我的表单帖子如下,读取另一个表:
<label for="ProgramListing"></label>
<select name="ProgramListing" style="width: 800px;" size="10" multiple id="ProgramListing">
<?php
$sql_program_listing = "SELECT * FROM program order by ProgramName ASC";
foreach($conn->query($sql_program_listing) as $row_program_listing){ ?>
<option value="<?=$row_program_listing["ProgramCode"];?>" <?php if ($row_programlisting["id_program"] == $registrant['id_program']) echo 'selected="selected"';?>><?=$row_program_listing["ProgramName"];?> (<?=$row_program_listing["ReleaseDate"] .")";?>
</option>
<?php } ?>
</select>
什么工作很好现在,我想添加以下信息:
$id_celebrity = $_POST['id_celebrity'];
$id_program_celebrity = $_POST['id_celebrity']+$_POST['ProgramListing'];
And i use:
foreach ($_POST['ProgramListing'] as $id_program)
{
$sql_connect_celebrity = "INSERT INTO
program_celebrity
(
id_program,
id_celebrity,
id_program_celebrity
)
VALUES
(?,?,?)";
$stmt = $conn->prepare($sql_connect_celebrity);
$stmt->bindValue(1, $id_program);
$stmt->bindValue(2, $id_celebrity);
$stmt->bindValue(3, $id_program_celebrity);
$stmt->execute();
}
但它的工作很好,当我发布只是一个选择,但我希望表单发布多个选择,并在表中注册它们。似乎不能得到它的权利,你知道我做错了什么?
修改表单
<select name="ProgramListing" style="width: 800px;" size="10" multiple id="ProgramListing">
<select name="ProgramListing[]" style="width: 800px;" size="10" multiple id="ProgramListing">