2017-08-30 100 views
-1

當我想創建一個帳戶,以測試是否插入到數據庫的工作我得到這個錯誤笨數據庫錯誤1064

錯誤編號:1064 您的SQL語法錯誤;檢查對應於您MariaDB的服務器版本的正確的語法使用手動接近 '其中0 = '在列測試' LIMIT 1' 2

SELECT * WHERE 0 = 'test' LIMIT 1 

文件名:C:/ XAMPP/htdocs中/ STG /系統/數據庫/ DB_driver.php

行號:691

我CONTROLER代碼Main.php:

$data = array(); 
$userData = array(); 
if($this->input->post('insert')){   

    $this->form_validation->set_rules('username', 
             'username', 
           'trim|required|is_unique|min_length[6]|max_length[20]'); 

    $this->form_validation->set_rules('password', 
             'password', 
       'trim|required|min_length[8]|max_length[20]|callback_is_password_strong'); 

    $this->form_validation->set_rules('conf_password', 
             'confirm password', 
             'required|matches[password]'); 

    $userData = array(
     'username' => $this->input->post('username'), 
     'password' => $this->input->post('password') 
    ); 

    if($this->form_validation->run() == true){ 
     $insert = $this->login_model->insert($userData); 
     if($insert){ 
      $this->session->set_userdata('success_msg', 
        'Your registration was successfully. Please login to your account.'); 
      redirect('login'); 
     }else{ 
      $data['error_msg'] = 'Some problems occured, please try again.'; 
     } 
    } 
} 
$data['user'] = $userData; 
//load the view 
$this->load->view('register', $data); 
} 

我的模型代碼LOGIN_MODE l.php:

public function insert($data = array()){ 
    //add created and modified data if not included 
    if(!array_key_exists("created", $data)){ 
     $data['created'] = date("Y-m-d H:i:s"); 
    } 
    if(!array_key_exists("modified", $data)){ 
     $data['modified'] = date("Y-m-d H:i:s"); 
    } 
} 

$insert = $this->db->insert('login' ,$data); 

if($insert){ 
    return $this->db->insert_id(); 
}else{ 
    return false; 
} 
echo $insert; 
} 
+0

笨什麼版本的? – coderodour

+0

3.1.5最新版本。 – Skully1

+0

我只是單擊提交按鈕來插入用戶到數據庫,但我得到這個錯誤。 – Skully1

回答

0

enter link description here來到這個錯誤,因爲你在使用is_unique以下行

$this->form_validation->set_rules('username', 'username', 'trim|required|is_unique|min_length[6]|max_length[20]'); 

所以語法是錯誤的,如果你使用is_unique然後

is_unique[table.field] 

其中表 - >替換爲您的用戶表,您存儲的用戶名爲 字段 - >用存儲用戶名的列名替換

is_unique背景是

select * from table_name where fields_name= your_varaible_value 

所以你沒有提到的表名,以及字段名,這就是爲什麼在這個查詢表名缺少

SELECT * WHERE 0 = 'test' LIMIT 1 // here table name is not present so Error Number: 1064 is occurred.