我試圖從數據庫提取成員信息,並得到這個錯誤:PHP MYSQL語法錯誤
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 '' FROM
users
WHEREuser_id
= 0' at line 8 That user does not exist.
我不知道要改變什麼,因爲我是新來的PHP。
我的錯誤代碼是:
<?php
function fetch_users() {
$result = mysql_query('SELECT `user_id` AS `id`, `user_username` AS `username` FROM `users`');
$users = array();
while (($row = mysql_fetch_assoc($result)) !== false) {
$users[] = $row;
}
return $users;
}
function fetch_user_info($uid) {
$uid = (int)$uid;
$sql = "SELECT
`user_username` AS `username`,
`user_firstname` AS `firstname`,
`user_lastname` AS `lastname`,
`user_email` AS `email`,
`user_about` AS `about`,
`user_location` AS `location`,
`user_gender` AS `gender`'
FROM `users`
WHERE `user_id` = {$uid}";
$result = mysql_query($sql);
/*Echo mysql_error();*/
return mysql_fetch_assoc($result);
} ?>
對不起,這裏是我的新錯誤信息:你的SQL語法錯誤;檢查與您的MySQL服務器版本相對應的手冊,以便在'FROM'用戶附近使用正確的語法WHERE'user_id'='0''在第9行 – user1155141 2012-02-11 21:01:12