1

I have an error with my website. Error:

Fatal 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 'get FROM login WHERE user_id = '252' LIMIT 1' at line 1' in /home/tregolap/public_html/config/class/universal.class.php:110 Stack trace: #0 /home/tregolap/public_html/config/class/universal.class.php(110): PDOStatement->execute(Array) #1 /home/tregolap/public_html/ajaxify/profile/profile_banner.php(89): universal->isOnline('252') #2 /home/tregolap/public_html/profile.php(71): include_once('/home/tregolap/...') #3 {main} thrown in /home/tregolap/public_html/config/class/universal.class.php on line 110

The universal.class.php code is:

if ($user != $session) {
      $query = $this->db->prepare("
        SELECT MAX(login_id) AS get 
        FROM login WHERE user_id = :id LIMIT 1");
      $query->execute(array(":id" => $user));

Profile banner error:

<?php
if($universal->isOnline($get_id)){
  echo "<span class='user_status'>online</span>";
}

Please someone tell me whats wrong or if I have to edit more codes to the topic so I edit it with full info,

Thanks!

Blag
  • 5,818
  • 2
  • 22
  • 45
  • 2
    `get` is a [reserved word](https://dev.mysql.com/doc/refman/5.7/en/keywords.html). You'll have to use quotes or backticks around it. Either one should work since it's a column alias. – aynber Oct 23 '17 at 21:36
  • 1
    Possible duplicate of [When to use single quotes, double quotes, and backticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql) – aynber Oct 23 '17 at 21:37

1 Answers1

0

In your SQL, get is one of the reserved words in MySQL. You can either change it to something that isn't a reserved word or put quotes/backticks around it.

if ($user != $session) {
  $query = $this->db->prepare("
    SELECT MAX(login_id) AS `get` 
    FROM login WHERE user_id = :id LIMIT 1");
  $query->execute(array(":id" => $user));
SameOldNick
  • 2,397
  • 24
  • 33