簡體   English   中英

如何使用nodejs和mysql制作購物車?

[英]How to make a shopping cart using nodejs and mysql?

我正在用 nodejs 和 mysql 構建一個電子商務網站。 我有用戶注冊和登錄以及帶有 CRUD 的產品頁面,但是修改購物車的最佳方法是什么?

我試圖將產品表中的數據插入另一個名為“購物車”的表中,但嘗試時沒有任何反應。

這是我已經擁有的一些內容:我將產品頁面和信息存儲在托管在 gearhost 上的 MySQL 數據庫中。 我也有用戶登錄頁面。 我只想知道如何將產品添加到購物車以及如何制作購物車頁面、從購物車中刪除、結帳等。

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});
});

console.log("Now you are on the products page!");
});

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");

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM