I want to select multiple choice and insert the values in database. How can I do this?
<select name="instructor" multiple>
<option value="9000">Zaher</option>
<option value="9001">Samih</option>
<option value="9010">Majd</option>
<select>
$instructor=$_GET['instructor'];
if(isset($_SESSION['courses']) && isset($_SESSION['semester'])){
$coursechosen= $_SESSION['courses'];
$semesterchosen=$_SESSION['semester'];
$query="Insert INTO coordinators(instructor_id,course_code,semester)
VALUES ('$instructor','$coursechosen','$semesterchosen')";
mysql_query($query);
}
<select name="instructor[]" multiple>
<option value="9000">Zaher</option>
<option value="9001">Samih</option>
<option value="9010">Majd</option>
<select>
// Your PHP code
<?php
foreach ($_GET['instructor'] as $value) {
$instructor.= $value.", ";
}
if(isset($_SESSION['courses']) && isset($_SESSION['semester'])){
$coursechosen= $_SESSION['courses'];
$semesterchosen=$_SESSION['semester'];
$query="Insert INTO coordinators(instructor_id,course_code,semester)
VALUES ('$instructor','$coursechosen','$semesterchosen')";
mysql_query($query);
}
?>
<select name="instructor[]" multiple>
<?php
foreach ($_POST['instructor'] as $icon)
{
///your insert code//
}?>
<select name="instructor[]" multiple>
<option value="9000">Zaher</option>
<option value="9001">Samih</option>
<option value="9010">Majd</option>
<select>
<input type="submit" value="send" name="send">
//php code
<?php
if (isset($_POST['send']))
{
if (isset($_POST['instructor']))
{
$instructor= implode(',',$_POST['instructor']);
$query="INSERT INTO `database` VALUES ('0','$instructor')";
mysql_query($query);
}
else
{
print "no selected";
}
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.