Skip to content
Advertisement

Syntax Error when using multiple parameter substitutions in a MYSQL Query

I need to Update MYSQL data using JS after I receive an AJAX Post request

I made a variable for the MYSQL Update Query and I’m passing in the field to be updated, new value, row to be updated as an array. But for some reason those variables are read with single quotes(') which, I believe, is causing me a syntax error.

Here’s the error I receive:

Error: ER_PARSE_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 ”Source_of_Phone_Number_’ = ‘Test’ WHERE ROW_ID = ‘1” at line 1`

Source_of_Phone_Number_ is the key_to_replace. Test is the newValue. 1 is the Row_ID.

Advertisement

Answer

There is a problem in function updatemysql(), which uses the following SQL :

var sql = "UPDATE mydb.mytable SET ? = ? WHERE ROW_ID = ?;";

You cannot pass a column name as a parameter.

You would need to change this to :

Accordingly, only two parameters should be passed to the query :

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement