0

PHP CODE

<?php
$imageId = $_GET ["a"];
$likerId = $_GET ["b"];

// connection to the database
$dbhandle = mysql_connect ( "localhost", "root", "" ) or die ( "Unable to connect to MySQL" );

// select a database to work with
$selected = mysql_select_db ( "taxogram", $dbhandle ) or die ( "Could not select login" );

// execute the SQL query and return records
$result = mysql_query ( "INSERT INTO liker ( imageId , likerId ) VALUES ( '$imageId' , '$likerId' ) " );
echo mysql_error () . "<br>";
if ($result == 1) {
    echo "sukses";
} else {
    echo "gagal";
}
?>

ERROR

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 ( imageId , likerId ) VALUES ( '1' , '2' )' at line 1 gagal

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
fikri
  • 17
  • 1
  • 6
  • 1
    `like` is a reserved keyword in sql, you need to use backticks to surround the word. – Andrei Jul 06 '15 at 15:45
  • you see i use backstick on values – fikri Jul 06 '15 at 15:47
  • Not values, they're unimportant to your question. you need to use them on the word like. – Andrei Jul 06 '15 at 15:48
  • 1
    By editing the question and changing the table name from `like` to `liker`, you're changing the basis of the question and likely confusing anyone who finds this in the future. You should leave it in the "broken" form so that others can learn from this. – Isaac Bennetch Jul 15 '15 at 02:05

1 Answers1

2

"like" is a reserved keyword.

$result = mysql_query ( "INSERT INTO `like` ( imageId , likerId ) VALUES ( '$imageId' , '$likerId' ) " );

Also note that mysql_ functions are deprecated. Use Mysqli or PDO instead.

Community
  • 1
  • 1
Matheno
  • 4,112
  • 6
  • 36
  • 53