发生数据库错误
错误号码:1062
关键'slug'重复输入'公司名称'
INSERT INTO ph_companies
(name
,slug
,about_us
,status
,datetime
)价值观('公司01','公司) name','pdc company:etc',1,'2016-06-02 12:25:09')
文件名:core / MY_Model.php
行号:61
控制器
function import(){
require_once APPPATH . 'libraries/excel_reader.php';
if(isset($_POST['submit'])){
$target = basename($_FILES['filepegawaiall']['name']) ;
move_uploaded_file($_FILES['filepegawaiall']['tmp_name'], $target);
$data = new Spreadsheet_Excel_Reader($_FILES['filepegawaiall']['name'],false);
$baris = $data->rowcount($sheet_index=0);
for ($i=2; $i<=$baris; $i++)
{
$save_data = array();
$save_data['name'] =$data->val($i,1);
$save_data['slug'] =$data->val($i,2);
$save_data['about_us'] =$data->val($i,3);
$save_data ['status'] = 1;
$save_data['datetime'] =$this->Company_model->getCurrentDatetime();
if(!$this->Company_model->__insert('ph_companies',$save_data)){
$this->session->set_flashdata('error', 'Record couldn\'n inserted. Please try again.');
}
else{
$this->session->set_flashdata('success', 'companies data created.');
//redirect('admin/company');
}
}
unlink($_FILES['filepegawaiall']['name']);
}
$this->load->view('admin/template/header');
$this->load->view('admin/company/import',$this->data);
$this->load->view('admin/template/footer');
}
指导我如何解决这个问题? !谢谢!!
答案 0 :(得分:0)
CREATE TABLE IF NOT EXISTS ph_companies ( company_id bigint(20) NOT NULL AUTO_INCREMENT, category_id int(255) NOT NULL, name varchar(250) NOT NULL, slug varchar(250) NOT NULL, logo varchar(100) NOT NULL, status tinyint(4) NOT NULL, about_us text NOT NULL, slider_images text NOT NULL, datetime datetime NOT NULL, PRIMARY KEY (company_id)) ;