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