目前我在codeigniter中创建了一个管理员问题。
不让我从表单中创建用户。我有一个SQL语法错误。并且不确定如果首次安装,如何确保将user_id设置为1.
错误
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `username` = 'admin'' at line 2
SELECT * WHERE `username` = 'admin'
Filename: C:\xampp\htdocs\codeigniter-cms\system\database\DB_driver.php
Line Number: 330
在模型上
function adminuser() {
$this->db->where('username', $this->input->post('username'));
$query = $this->db->get($this->input->post('database'));
if($query->num_rows > 0){
echo '<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a><strong>';
echo "Username already taken";
echo '</strong></div>';
}else{
$query_user = array(
'username' => $this->input->post('username'),
'password' => sha1($this->input->post('password')),
'email' => $this->input->post('email')
);
$insert = $this->db->insert($this->input->post('database'), $query_user);
return $insert;
}
}
答案 0 :(得分:0)
我建议您学习ActiveRecord文档页面。 http://ellislab.com/codeigniter/user-guide/database/active_record.html
您错过了FROM
...在输出错误消息中非常清楚。
试试这个,
$username = $this->input->post('username');
$query = $this->db->get_where('mytable', array('username' => $username));