這裏插入圖像的路徑到數據庫是我的控制器插入代碼
此代碼插入圖像插入圖像路徑文件夾,但路徑沒有在數據庫中保存。所示使用笨
function add_hotel() {
//validate form input
$this->form_validation->set_rules('hotelname', 'Hotel Name', 'required|xss_clean');
$this->form_validation->set_rules('hotellocation', 'Hotel Location', 'required|xss_clean');
$this->form_validation->set_rules('hotelphone', 'Hotel Phone', 'required|xss_clean');
$this->form_validation->set_rules('hotelimg', 'Hotel Image ', 'callback__image_upload');
$this->form_validation->set_rules('hotelabout', 'Hotel About', 'required|xss_clean');
if ($this->form_validation->run() == true)
{
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000000';
$config['overwrite'] = TRUE;
$config['remove_spaces'] = TRUE;
$config['encrypt_name'] = FALSE;
$this->load->library('upload', $config);
$field_name = "hotelimg";
if (! $this->upload->do_upload($field_name))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('admin/add_hotel', $error);
}
else {
$data = array(
'hotelname' => $this->input->post('hotelname'),
'hotellocation' => $this->input->post('hotellocation'),
'hotelphone' => $this->input->post('hotelphone'),
'hotelimg' => $this->upload->data('hotelimg'),
'hotelabout' => $this->input->post('hotelabout')
);
print_r($data);
$this->db->insert('hotel_content', $data);
$this->session->set_flashdata('message', "<p>Hotel added successfully.</p>");
redirect(base_url().'index.php/admin/hotel_controller/index');
}
錯誤是:
遇到甲PHP錯誤
嚴重性:注意
消息:Array對字符串的轉換
文件名:MySQL的/ mysql_driver.php
行號:552
and
數據庫出錯:
錯誤編號:1054
未知列在 '字段列表'
INSERT INTO`hotel_content` '陣列'(`hotelname`,`hotellocation`,`hotelphone` ,'hotelimg`,`hotelabout`)VALUES('hotel5','hyd','0402365477',Array,'welcome')
文件名:G:\ wamp \ www \ CodeIgniter \ system \ database \ DB_driver.php
行號:330
我需要在數據庫中插入路徑。誰能幫我?