Skip to content
Advertisement

NodeJS MySQL apostrophe reduplication with INSERT query

I’m doing my project Nodejs and MySQL and I have some problem with query with apostrophe. I got all of the data from github api and it normally works fine. but If data have single apostrophe(‘), it will get Syntax Error.

And the Error is like this.

At first, I was thinking about using regular expressions to get rid of all ‘ but this is not a good way to correct the original data itself.

I search the solutions in google but it’s really hard to find with this problem. Is there any google idea or solutions?

Advertisement

Answer

I solved the problem myself. @scetiner helps me about the keyword.

I create array and put it all variables. and because of the SQL Injection attack, I have to add placeholders(I’m not sure what is called. it’s look like ?,?,?,?,?)

Anyway Here’s my code that I modified.

and then it works fine like this

: Console

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