adding listbox value with multi value select to sql database in php -
i trying add multiple values sql table (program_celebrity) form post, have in form post following, reads table this:
<label for="programlisting"></label> <select name="programlisting" style="width: 800px;" size="10" multiple id="programlisting"> <?php $sql_program_listing = "select * program order programname asc"; foreach($conn->query($sql_program_listing) $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>
what works fine add information comes follows:
$id_celebrity = $_post['id_celebrity']; $id_program_celebrity = $_post['id_celebrity']+$_post['programlisting'];
and use:
foreach ($_post['programlisting'] $id_program) { $sql_connect_celebrity = "insert 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(); }
but works fine when post 1 selection, form post multiple selections , register them in table. can't seem right, ideas doing wrong?
change form
<select name="programlisting" style="width: 800px;" size="10" multiple id="programlisting">
to
<select name="programlisting[]" style="width: 800px;" size="10" multiple id="programlisting">
Comments
Post a Comment