-3

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 'like= 1 where ID =57' at line 1

This is the code with update, all names of attributes and table are checked.

<?php
    include("../connect.php");
    if (session_id() == "")
    session_start();
    $id = $_GET['id'];
    $update = "Update  komentari  set like = 1 where ID=$id";

        if (mysql_query($update)) {

            echo 'success';
        }
        else {
        echo    mysql_error();


        }

    ?>
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • 5
    `like` is a [MySQL reserved word](http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html).... if you have to use it as a column or table name, then you must enclose it in backticks (`) – Mark Baker Sep 05 '14 at 18:55
  • LIKE is a reserved word. Use Backticks to escape – StuartLC Sep 05 '14 at 18:55
  • possible duplicate of [Syntax error due to using a reserved word as a table or column name in MySQL](http://stackoverflow.com/questions/23446377/syntax-error-due-to-using-a-reserved-word-as-a-table-or-column-name-in-mysql) – Funk Forty Niner Sep 05 '14 at 20:51

2 Answers2

3

like is a reserved word. You cannot use it "raw" in the query. Try this instead:

UPDATE komentari SET `like` = 1 WHERE ID = $id
                     ^----^---note the backticks

Full list here: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

Marc B
  • 356,200
  • 43
  • 426
  • 500
3

like is an SQL reserved word. You'll need to either use a different column name, or quote it with backticks as `like` whenever you refer to it.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578