I have a list of days in my database created with the SET datatype.
SET('Mon','Tue','Wed','Thr','Fri','Sat','Sun')
I want a user to be able to select multiple days to put into the database using a multiple select dropdown:
Mon
Tue
Wed
Thr
Fri
Sat
Sun
How can I grab the data from this dropdown to insert into my mysql query?
Right now my query is like this:
$sql2 = " UPDATE tblFacilityHrsDateTimes SET `startEventDate`='{$_POST['startEventDate']}',`endEventDate`='{$_POST['endEventDate']}', `startTime`='{$_POST['startTime']}',`endTime`='{$_POST['endTime']}',`recurrence`='{$_POST['recurrence']},`finalDate`='{$_POST['finalDate']}' WHERE `id` = '$id' "; $mysqli->query($sql2) or die($mysqli->error);
Currently with the select box as is, it only grabs one of the days selected by a user.
解决方案
First, Your select should have name with square brackets:
This way when a user select more values (options) and submit the form You will receive an array of values he selected.
Then You have to loop through this array and insert each record:
foreach($_POST['days'] as $k => $v) {
// here do the INSERT query with value $v
}
But Your query under the select box is telling us that this is not the end of the story...