我尝试将一个表单插入到不同的一个表名是匹马,其他表名是 filename_img 查询意味着我在一个表中有不同的字段而我想要的其他字段将图像插入到其他表但我的一个表单插入字段和图像这是我的模型,请确认我的查询我错了,因为显示查询显示查询错误谢谢进展
模型
function horses_insert($data){
$postcode = addslashes($data['postcode']);
$height = addslashes($data['height']);
$breed_id = addslashes($data['breed_id']);
$colour_id = addslashes($data['colour_id']);
$age = addslashes($data['age']);
$gender = addslashes($data['gender']);
$name = addslashes($data['name']);
$price = addslashes($data['price']);
$description = addslashes($data['description']);
// $image = addslashes($data['image']);
$status = addslashes($data['status']);
$price_currency = addslashes($data['price_currency']);
$height_unit = addslashes($data['height_unit']);
$is_urgent = addslashes($data['is_urgent']);
$is_featured = addslashes($data['is_featured']);
$is_spotlight = addslashes($data['is_spotlight']);
$is_sale = addslashes($data['is_sale']);
if($is_urgent=="on"){
$is_urgent="1";
}else{
$is_urgent="0";
}
if($is_featured=="on"){
$is_featured="1";
}else{
$is_featured="0";
}
if($is_spotlight=="on"){
$is_spotlight="1";
}else{
$is_spotlight="0";
}
if($is_sale=="on"){
$is_sale="1";
}else{
$is_sale="0";
}
$result= $this->db->query("INSERT INTO horses (postcode,height,breed_id,colour_id,age,gender,name,price, description,is_urgent,is_featured,is_spotlight,is_sale,status,price_currency,height_unit) VALUES ('$postcode','$height','$breed_id','$colour_id','$age','$gender','$name','$price','$description','$is_urgent','$is_featured','$is_spotlight','$is_sale','$status','$price_currency','$height_unit')");
$id=$this->db->insert_id();
//return $id;
if ($result) {
$userfile = addslashes($data['userfile']);
$query= $this->db->query("INSERT INTO filename_img (userfile,$id) VALUES ('$userfile','')");
$id=$this->db->insert_id();
return $id;
}
}
答案 0 :(得分:1)
试试这个:
$userfile = addslashes($data['userfile']);
$commaSeprartedFilesName = implode(",",$userfile);
$query= $this->db->query("INSERT INTO filename_img (userfile,id) VALUES ('$commaSeprartedFilesName',$id)");
$id=$this->db->insert_id();
return $id;
UserFile应该是html中的数组,如