0

could you tell me what is wrong with this query? I have been looking for almost an hour but i could not see any syntax mistake..

$query = $database->connection->prepare(
        "SELECT 
        n.from_id AS friend_id, 
        n.type AS type,
        n.created_date AS time,
        u.user_profile_picture AS profile_picture, 
        u.user_firstname AS friend_firstname, 
        u.user_lastname AS friend_lastname, 
        FROM notifications n INNER JOIN users u ON u.user_id = n.from_id 
        WHERE n.to_id = :user_id AND n.checked = 1");   

    $query->bindValue(':user_id', $user_id, PDO::PARAM_STR); 
    $query->execute(); 

And this is error:

Uncaught exception 'PDOException' with message

'SQLSTATE[42000]: Syntax error or access violation: 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 'FROM notifications n INNER JOIN users u ON u.user_id = n.from_id WHERE n.to_id =' at line 8' in

Mad Dog Tannen
  • 7,129
  • 5
  • 31
  • 55
suyilmaz
  • 155
  • 1
  • 8

2 Answers2

3

Remove the , before FROM

SELECT 
        n.from_id AS friend_id, 
        n.type AS type,
        n.created_date AS time,
        u.user_profile_picture AS profile_picture, 
        u.user_firstname AS friend_firstname, 
        u.user_lastname AS friend_lastname 
        FROM notifications n INNER JOIN users u ON u.user_id = n.from_id 
        WHERE n.to_id = :user_id AND n.checked = 1
Mad Dog Tannen
  • 7,129
  • 5
  • 31
  • 55
0

You have to remove the comma at the end of line:

u.user_lastname AS friend_lastname, 
George
  • 467
  • 3
  • 3