title: MySQL Query Error with Node Js
body: <p>I am using MySQL with Node JS and I am detecting whether an existing user is already in the database. This code below is what I have been using:</p>
  
  <pre><code>var username = "RandomUsername";
  var email = "RandomEmail@gmail.com";    
  var sql = "SELECT * FROM users WHERE user_name = " + username + " OR user_email = " + email;
  connection.query(sql, function(err, rows, fields) {
            if (err) throw err;
            if (rows.length !== 0) {
              errors.push("Sorry, that email or username already being used.");
  }
  </code></pre>
  
  <p>This is the error message I am getting:</p>
  
  <pre><code>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 'cameroncjones4'' OR user_email = ''cameroncjones4''' at line 1
  at Query.Sequence._packetToError (/Users/CameronJones/Desktop/NodeJS/LoginSystem/node_modules/mysql/lib/protocol/sequences/Sequence.js:48:14)
  at Query.ErrorPacket (/Users/CameronJones/Desktop/NodeJS/LoginSystem/node_modules/mysql/lib/protocol/sequences/Query.js:83:18)
  at Protocol._parsePacket (/Users/CameronJones/Desktop/NodeJS/LoginSystem/node_modules/mysql/lib/protocol/Protocol.js:271:23)
  at Parser.write (/Users/CameronJones/Desktop/NodeJS/LoginSystem/node_modules/mysql/lib/protocol/Parser.js:77:12)
  at Protocol.write (/Users/CameronJones/Desktop/NodeJS/LoginSystem/node_modules/mysql/lib/protocol/Protocol.js:39:16)
  at Socket.&lt;anonymous&gt; (/Users/CameronJones/Desktop/NodeJS/LoginSystem/node_modules/mysql/lib/Connection.js:96:28)
  at Socket.emit (events.js:107:17)
  at readableAddChunk (_stream_readable.js:163:16)
  at Socket.Readable.push (_stream_readable.js:126:10)
  at TCP.onread (net.js:538:20)
  --------------------
  at Protocol._enqueue (/Users/CameronJones/Desktop/NodeJS/LoginSystem/node_modules/mysql/lib/protocol/Protocol.js:135:48)
  at Connection.query (/Users/CameronJones/Desktop/NodeJS/LoginSystem/node_modules/mysql/lib/Connection.js:201:25)
  at IncomingMessage.&lt;anonymous&gt; (/Users/CameronJones/Desktop/NodeJS/LoginSystem/app.js:86:20)
  at IncomingMessage.emit (events.js:107:17)
  at IncomingMessage.Readable.read (_stream_readable.js:373:10)
  at flow (_stream_readable.js:750:26)
  at resume_ (_stream_readable.js:730:3)
  at _stream_readable.js:717:7
  at process._tickCallback (node.js:355:11)
  </code></pre>
  
  <p>Help with solving this problem appreciated.</p>