I'm trying to create a basic storefront through node.js and have to update the stock_quantity based on user input, but i am having trouble figuring out how to not set the value, but subtract from the current value.
I have provided a function of my code that would run to get this information. I am able to set the value through workbench, but unable through node.js I just get a OKPacket {fieldCount:0, affectedRows:0...etc).Any help is appreciated.
products = table, stock_quantity = column, item_id = column/ primary key
//updates the inventory and gives the total price and item description
function checkOut(answer, amount) {
var item_id = answer;
var quantity = amount;
var stock_quantity = stock_quantity - quantity;
// answer and amount have successfully moved!!
console.log("\n(consolelog)quantity: " + quantity + "\n(consolelog)item_id: " + item_id);
connection.query("UPDATE products SET stock_quantity = ? WHERE item_id = ?",
['stock_quantity', 'item_id'], function(error, results) {
if (error) throw error;
// console.log("\nProduct Name: " + results.product_name + "\nQuantity: " + results.stock_quantity);
console.log(results);
// shopAgain();
});
}
via Christian A
No comments:
Post a Comment