2017-08-30 82 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.