'Importing value from MySQL into JavaScript as variable
I'm trying to make a Database for a film distrubution. i got 3 tables: client, movies and borrowing and I want to get the price value from the movies table and multiply it with the days rented to get the final costs for borrowing it for x days. How can i import the value of the price and calculate with it? i got:
app.get("/ausleihen/get/kosten", function(req,res) {
const moviename= req.body.filmName;
const sqlGet = "SELECT costs FROM movies WHERE moviename= ?;"
connection.query(sqlGet, moviename, (err, result) =>{
varCosts=result;
});
});
app.post("/ausleihen/insert", (req, res)=>{
const prename= req.body.prename;
const lastname= req.body.lastname;
const moeviename= req.body.moeviename;
const begin= req.body.begin;
const end= req.body.end;
const begin1= new Date(req.body.begin).valueOf();
const end1= new Date(req.body.end).valueOf();
const diff = Math.abs(end1-begin1);
const diffDays = Math.ceil(diff / (1000*60*60*24));
const costs= diffDays;
const sqlInsert = "INSERT INTO ausleihen (moviename, prename, lastname, begin, end, costs) VALUES (?,?,?,moviename, prename, lastname, begin, end, costs], (err, result)=>{
console.log(err);
})
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
