Reputation: 17
Can someone tell me why this isn't updating? The id exists in the table but it wont update.
let sql = `UPDATE Users
SET MMR = MMR-30, Lose = Lose+1
WHERE Nameid = ${data[0].Team1id}`;
db.run(sql, data, function(err) {
if (err) {
return console.error(err.message);
}
console.log(`Row(s) updated: ${this.changes}`);
});
But it updates when I edit to this, but I need it to work with Nameid. Because if the team1 changes its name it wont find itself in the table! Meanwhile you cant change your id.
let sql = `UPDATE Users
SET MMR = MMR-30, Lose = Lose+1
WHERE Name = "${data[0].Team1name}"`; // this was changed
db.run(sql, data, function(err) {
if (err) {
return console.error(err.message);
}
console.log(`Row(s) updated: ${this.changes}`);
});
Got it! Im gonna leave it here if someone stumbles with the same problem someday!
let sql1 = `UPDATE Users
SET MMR = MMR+25, Win= Win+1
WHERE Nameid = ?`;
db.run(sql1, data[0].Team1id, function(err) {
if (err) {
return console.error(err.message);
}
console.log(`Row(s) updated: ${this.changes}`);
});
Upvotes: 0
Views: 31
Reputation: 26
Try to console.log()
the data[0].Team1id
and see what it gives,
I really can't see any problem in the code, just that team1id
could be incorrect.
Another thing...
You need to secure the SQL, it's vulnerable for SQL Injection. Search for "node.js secure for MySQL injection".
Upvotes: 1