2015-11-01 12:44
浏览 548

查询无效:SQL语法中存在错误; 语法在附近使用

I have this problem error and I don't know how to solve it. I know what so many have issues like my issue but I can not orient.


Invalid query: 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 `user` WHERE `id` = 0' at line 6


function fetch_users(){
$result = mysql_query('SELECT `id` AS `id`, `username` AS `username` FROM `user`');

$users = array();

while(($row = mysql_fetch_assoc($result)) !== false){
       $users[] = $row;

   return $users;


// fetches profile information for the given user.
function fetch_user_info($id){
   $id = (int)$id;

   $sql = "SELECT 
               `username` AS `username`,
               `firstname` AS `firstname`,
               `lastname` AS `lastname`,
               `email` AS `email`,
             FROM `user` WHERE `id` = {$id}";

      $result = mysql_query($sql);
      if (!$result) {
   die('Invalid query: ' . mysql_error());

      return mysql_fetch_assoc($result);

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题