0

With this php/mysql query:

mysql_query("INSERT INTO Follows (User, Following, Type) VALUES ('$_COOKIE[user]', '$genre', 'Genre'")

I am getting the syntax 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 '' at line 1"

I see nothing wrong with this syntax. Does anyone else?

Max
  • 37
  • 2
  • 4

3 Answers3

6

You have a missing parenthesis:

mysql_query("INSERT INTO ... VALUES (... , 'Genre'")

Should be:

mysql_query("INSERT INTO ... VALUES (... , 'Genre')")
                                                  ^

You also have an SQL injection vulnerability in your code. Use mysql_real_escape_string or parameterized queries. Related:

Community
  • 1
  • 1
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
0

You did not close your last bracket in the query.

mysql_query("INSERT INTO Follows (User, Following, Type) VALUES ('$_COOKIE[user]', '$genre', 'Genre')")
Mob
  • 10,958
  • 6
  • 41
  • 58
-1

The error is that you're not closing your MySQL statement with the corresponding bracket.

Yours:

mysql_query("INSERT INTO Follows (User, Following, Type) VALUES ('$_COOKIE[user]', '$genre', 'Genre'");

Correct:

mysql_query("INSERT INTO Follows (User, Following, Type) VALUES ('$_COOKIE[user]', '$genre', 'Genre')");
Jules
  • 7,148
  • 6
  • 26
  • 50