Я хочу сохранить значение, которое я выбрал после отправки формы.
<select name="student[]" class="selectpicker" multiple title="Click here.." data-width="auto" data-live-search="true" required>
<?php
if (isset($_POST['submit'])){
$selected = $_POST['studname'];
$qry = "Select studtbl.stud_id,concat(studtbl.fname,' ',
substring(studtbl.mname, 1,1),'. ',studtbl.lname) as Name from studtbl";
$result = mysqli_query($conn, $qry);
while($row = mysqli_fetch_array($result))
{
extract($row);
echo '<option value="'.$stud_id.'" '.(($stud_id ==
$selected)? 'selected="selected"':"" >'.$Name.'</option>';
}
}else{
$qry = "Select studtbl.stud_id,concat(studtbl.fname,' ',
substring(studtbl.mname, 1,1),'. ',studtbl.lname) as Name from studtbl";
$result = mysqli_query($conn, $qry);
while($row = mysqli_fetch_array($result))
{
extract($row);
echo '<option value="'.$stud_id.'" >'.$Name.'</option>';
}
}
?>
</select>
<input type='submit' class="btn btn-primary" name='submit' value='Create
Account' />
<select name="student[]" class="selectpicker" multiple title="Click here.." data-width="auto" data-live-search="true" required>
<?php
if (isset($_POST['submit'])){
$selected = $_POST['student']; // <---- multi-selects come in as Array
$qry = "Select studtbl.stud_id,concat(studtbl.fname,' ',
substring(studtbl.mname, 1,1),'. ',studtbl.lname) as Name from studtbl";
$result = mysqli_query($conn, $qry);
while($row = mysqli_fetch_array($result))
{
extract($row);
// if the current ID is inside the POST-ed Array - mark as SELECTED
echo '<option value="'.$stud_id.'" '.(in_array($stud_id, $selected) ? 'selected="selected"': "").'>'.$Name.'</option>';
}
}else{
$qry = "Select studtbl.stud_id,concat(studtbl.fname,' ',
substring(studtbl.mname, 1,1),'. ',studtbl.lname) as Name from studtbl";
$result = mysqli_query($conn, $qry);
while($row = mysqli_fetch_array($result))
{
extract($row);
echo '<option value="'.$stud_id.'" >'.$Name.'</option>';
}
}
?>
</select>
<input type='submit' class="btn btn-primary" name='submit' value='Create
Account' />
Других решений пока нет …