这是我的控制器插入代码
此代码将图像插入图像路径文件夹,但路径未保存在数据库中。
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 错误
严重性:通知
消息:数组到字符串转换
文件名:mysql/mysql_driver.php
行号:552
和
发生数据库错误:
错误号:1054
“字段列表”中的未知列“数组”
插入到“hotel_content”(“hotelname”、“hotellocation”、“hotelphone”、“hotelimg”、“hotelabout”)值(“hotel5”、“hyd”、 '0402365477', Array, 'welcome')
文件名:G:\wamp\www\CodeIgniter\system\database\DB_driver.php
行号:330
我需要在数据库中插入路径。谁能帮我?