MySQL "unknown column" error message
I am doing a 开发者_如何学JAVAPHP tutorial that uses the code below to insert a new user into a database. In the video tutorial I am following, the code works, but when I tried it I got the following error message
Database query failed: Unknown column
'password' in 'field list'
Can someone explain what's wrong? Why is there only a problem with password? but it worked o.k. in the tutorial?
$sql = "INSERT INTO users (id, username, password, first_name, last_name) ";
$sql .= "VALUES (1, 'kskoglund', 'secretpwd', 'Kevin', 'Skoglund')";
$result = $database->query($sql);
public function query($sql) { $result
= mysql_query($sql, $this->connection);
return $result;
}
I used my crystal ball and can see that in phpMyAdmin, you have chosen your test database - therefore it works.
In PHP code however, you have chosen the server but not the correct database. You are still using the default database.
place password in backtick like
$sql = "INSERT INTO users (id, username, `password`, first_name, last_name) ";
and also go to phpmyadmin and edit your password attribute, there may be space before password column
The word 'password' in MySQL is a reserved word. You need to ensure it is wrapped in ``.
精彩评论