php下拉列表读取mysql数据,使用PHP从多选下拉列表中获取数据以插入MySQL

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...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值