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?

4
  • It depends what the values of those variables are... you should really be escaping them Commented Oct 21, 2011 at 21:31
  • 2
    Among other concerns, you're missing the ending ) for VALUES Commented Oct 21, 2011 at 21:31
  • 1
    Seriously?! It's 2011 and we're still using string interpolation for SQL queries? Commented Oct 21, 2011 at 21:31
  • Yep, chances are the variables are causing your headache, one of them contains an apostrophe or slash or is empty altogether. Commented Oct 21, 2011 at 21:33

3 Answers 3

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:

Sign up to request clarification or add additional context in comments.

Comments

0

You did not close your last bracket in the query.

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

Comments

-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')");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.