我想制作购物车,但不确定如何做。 我已经设置了用户登录注册和产品页面。 这是我到目前为止拥有的代码,不包括我的登录注册代码。
app.get("/", function(req, res){
res.render("index");
console.log("Home page")
console.log('Cookies: ', req.cookies);
});
app.get('/products',function(req, res){
let sql = 'SELECT * FROM item'
let query = db.query(sql, (err, res1) => {
if(err) throw err;
console.log(res1);
res.render('products', {res1});
});
});
app.get('/newproduct',function(req,res){
res.render('newproduct')
});
app.post('/newproduct',function(req,res){
let sampleFile = req.files.sampleFile
var filename = sampleFile.name;
sampleFile.mv('./images/'+ filename, function(err){
});
let sql = 'INSERT INTO item (title, brand,
image,genre,description,quality,price)
VALUES ("'+req.body.title+'", "'+req.body.brand+'", "'+filename+'","'+req.body.genre+'","'+req.body.description+'","'+req.body.
quality+'", '+req.body.price+')'
let query = db.query(sql,(err,res) =>{
if(err) throw err;
});
res.redirect("/products");
});