MySQL Forums
Forum List  »  Connector/Node.js

Re: nodejs/socket.io/mysql
Posted by: Rui Quelhas
Date: June 30, 2020 11:31AM

Hi Raymond,

glad you found a solution. However, let me elaborate a bit on the problem given what you mention. In this case, the lack of backticks in the table name and column name identifiers is not the issue.

The issue is that you need to "encode" the JavaScript type as a proper MySQL data type that fits the column where you are trying to insert. Which means that by not wrapping the data variable with quotes (single or double) you are basically sending an identifier (and not a literal value) on "VALUES ()" to the server.

So, the issue could be fixed only by replacing

var sql = "insert into room (roomid) values ("+data+");"

with

var sql = "insert into room (roomid) values ('"+data+"');"

or, using template strings:

var sql = `insert into room (roomid) values ('${data}');`

Options: ReplyQuote


Subject
Written By
Posted
June 26, 2020 12:52PM
Re: nodejs/socket.io/mysql
June 30, 2020 11:31AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.