-1

I'm really confused right now, keep getting this MySQL error:

Error updating record: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'condition='-78' WHERE id='2'' at line 1

While I KNOW that condition is correct, when I remove the condition='".$data['condition']."' from the update record, the update is being processed but when I add that, it fails.

The field in the database is VARCHAR (6), just like all the other fields.

What could be the issue?

Tom
  • 4,257
  • 6
  • 33
  • 49
C Kolkman
  • 29
  • 1
  • 7

2 Answers2

3

condition is a MySQL keyword. You need to enclose it with backticks if you're using it as a column name.

`condition`='-78' WHERE id='2'

Take care: This is the backtick symbol, not the single quote.

Ben Hillier
  • 2,126
  • 1
  • 10
  • 15
1

condition is a reserved word in MySQL.

You can see the full reserved word list here

You need to wrap condition in backticks;

"UPDATE ..... WHERE `condition`= '".$data['condition']."'";

A note for next time: Please include as much code as is sensible next time. Otherwise it is trickier for people to help you.

Tom
  • 4,257
  • 6
  • 33
  • 49
  • 1
    Thank you I never thought of that because with the same query but only INSERT instead of UPDATE, there is no problem, also not with condition. But this was the solution, will mark your answer as soon as I can :) – C Kolkman Mar 20 '17 at 09:50