1
我试图通过节点JS在数据库中插入数据。代码工作正常,显示“记录插入”消息,但在MySQL中没有更新行。节点JS MySQL - 插入数据..数据库中没有行更新
这是我在哪里执行插入操作
connection.query('SELECT * FROM menu WHERE item_name=\'' + userResponces[2].toLowerCase() + '\'', function(err, rows){
if (err) throw err;
else{
i_id = rows[0].item_id;
console.log('i_id ' + i_id);
connection.query('INSERT INTO customer VALUES(default,' + c_name + ',' + c_addr + ',' + c_mob + ')', function(err, res){
if(err.fatal){
console.log(''+err.message);
}
else{
console.log("Record Inserted");
connection.query('SELECT MAX(customer_id) AS c_id FROM customer', function(err, res){
if(err) throw err;
else{
c_id = parseInt(res[0].c_id) + 1;
console.log('c_id ' + c_id);
console.log(i_id + ' ' + c_id + ' ' + qty);
connection.query('INSERT INTO order1() VALUES(default,' + i_id + ',' + c_id + ',' + qty + ',1)', function(err, res){
if(err) throw err;
else
console.log("Record Inserted");
});
}
});
}
});
}
});
在上面的代码中的SELECT语句可以正常使用的代码,在连接,以便无疑是没有错误。这仍然是为了连接。
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'nodeuser',
password : 'password',
database : 'foodorder'
});
connection.connect(function(err){
if(!err) {
console.log("Database is connected ...");
} else {
console.log("Error connecting database ...");
}
});
感谢您的帮助:) –