我正在将数组数据插入数据库。使用像这样的内爆函数
$customers = implode(',', $_POST['customer_type']);
插入像这样的数据
$query = "INSERT INTO customers (id, customers) VALUES ('','".$customers."')";
$mysqli->query($query);
如果我选择了多个客户,那么我的插入查询将非常有效。若我选择单个客户,那个么我的查询不会向数据库中插入任何数据。
所以请建议我怎么做?
请尝试以下操作:-
if(is_array($_POST['customer_type'])){
$customers = implode(',', $_POST['customer_type']);
} else {
$customers = $_POST['customer_type'];
}