php - Invalid query: You have an error in your SQL syntax; syntax to use near -


i have problem error , don't know how solve it. know many have issues issue can not orient.

problem:

invalid query: have error in sql syntax; check manual corresponds mysql server version right syntax use near 'from `user` `id` = 0' @ line 6 

code:

<?php function fetch_users(){ $result = mysql_query('select `id` `id`, `username` `username` `user`');  $users = array();  while(($row = mysql_fetch_assoc($result)) !== false){        $users[] = $row;    }     return $users;  }  // fetches profile information given user. function fetch_user_info($id){    $id = (int)$id;     $sql = "select                 `username` `username`,                `firstname` `firstname`,                `lastname` `lastname`,                `email` `email`,              `user` `id` = {$id}";        $result = mysql_query($sql);       if (!$result) {    die('invalid query: ' . mysql_error());    }        return mysql_fetch_assoc($result); }   ?> 

remove comma after last column:

$sql = "select               `username` `username`,              `firstname` `firstname`,              `lastname` `lastname`,              `email` `email`              -- here          `user` `id` = {$id}"; 

also don't need alias same name column:

$sql = "select               `username`,              `firstname`,              `lastname`,              `email`            `user` `id` = {$id}"; 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -