I am writing an sql query in node.js that always gives error: unkown column in field list, whenever i try to use a string as a value, but not another data type
CREATE TABLE tableform (
id int auto_increment primary key,
billID int,
dinnerID int,
url text,
FOREIGN KEY (billID) REFERENCES bill(billID),
FOREIGN KEY (dinnerID) REFERENCES dinner(dinnerID)
);
updatedatabase: function (billID, dinnerID, tablename, restaurant) {
conn.query('insert into tableform(billID,dinnerID,url) values (' +billID+ ',' +dinnerID+ ',' + number + ');',
function (err, results, fields) {
if (err) throw err;
else console.log('update');
});
}
In the code shown, if I change variable number to 4 (i.e. var number = 4; on the 3rd line, the query works fine. If it's a string (as shown in the code), the error message appears.
There shouldn't be any error messages and the code should run fine if number is a string. However, the aforementioned error message still shows.
Errors:
Error: Unknown column 'sfsdfsd' in 'field list'
at Packet.asError (c:\Users\Documents\GitHub\node_modules\mysql2\lib\packets\packet.js:684:17)
at Query.execute (c:\Users\Documents\GitHub\node_modules\mysql2\lib\commands\command.js:28:26)
at Connection.handlePacket (c:\Users\Documents\GitHub\node_modules\mysql2\lib\connection.js:455:32)
at PacketParser.onPacket (c:\Users\Documents\GitHub\node_modules\mysql2\lib\connection.js:73:18)
at PacketParser.executeStart (c:\Users\Documents\GitHub\node_modules\mysql2\lib\packet_parser.js:75:16)
at Socket.<anonymous> (c:\Users\Documents\GitHub\node_modules\mysql2\lib\connection.js:80:31)
at Socket.emit (events.js:189:13)
at Socket.EventEmitter.emit (domain.js:441:20)
at addChunk (_stream_readable.js:284:12)
at readableAddChunk (_stream_readable.js:265:11)
directoravailabilitiesinputformtable, add it to the question