Error: ER_BAD_FIELD_ERROR: Unknown column 'asd123' in 'field list' in node js

mysql, node.js, sql

Solution

Try the below query, the variables `'+userID+'` and `'+socketID+'` are modified as `"'+userID+'"` and `"'+socketID+'"`:

connection.query(
  'callpushnotificationdb.spUpdateSocketID("'+userID+'","'+socketID+'");'
)
.on('end',function(){
  console.log('User '+ userID+' has updated his socketID to '+socketID);
});

Problem

I receive this error when I'm trying to update table in phpmyadmin can anyone tell me what's wrong please this is the table ``` create table ms_registereduser(userID Varchar(10),socketID Varchar(255)); ``` this is my server.js ``` var http = require("http"); var mysql = require('mysql'); var connection = mysql.createConnection({ host : 'localhost', user : 'root', password : '', database : 'pushnotificationdb' }); var userID = "1234567890", socketID = "asd123"; http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); }).listen(1111); connection.connect(); connection.query('callpushnotificationdb.spUpdateSocketID('+userID+','+socketID+');').on('end',function() { console.log('User '+ userID+' has updated his socketID to '+socketID); }); connection.end(); ``` and this is my spUpdateSocketID with '//' as a delimiter ``` DROP PROCEDURE IF EXISTS spUpdateSocketID// CREATE PROCEDURE spUpdateSocketID(IN userID Varchar(10) ,IN socketID Varchar(255)) BEGIN set @userID = userID; set @socketID = socketID; set @s = CONCAT('UPDATE ms_registereduser SET socketID = @socketID WHERE userID = @userID'); PREPARE stmt FROM @s; EXECUTE stmt; DEALLOCATE PREPARE stmt; END// ``` If I try to call the procedure in phpmyadmin like this ``` call pushnotificationdb.spUpdateSocketID('1234567890','asd123'); ``` it works, but if I try to call it from node.js it gave me error like this Error: ER_BAD_FIELD_ERROR: Unknown column 'asd123' in 'field list' , please help

Original source

Related problems