【问题标题】:How to make a shopping cart using nodejs and mysql?如何使用 nodejs 和 mysql 制作购物车?
【发布时间】:2019-07-17 13:15:32
【问题描述】:

我正在使用 nodejs 和 mysql 构建一个电子商务网站。我有 CRUD 的用户注册、登录和产品页面,但是修改购物车的最佳方法是什么?

我尝试将 products 表中的数据插入另一个名为 cart 的表中,但尝试时没有任何反应。

【问题讨论】:

  • 请展示您正在尝试的内容,我们或许能够确定您遇到问题的地方。事实上,这个问题太宽泛了。
  • 欢迎来到 SO。你的问题太模糊了,任何人都无法提供任何有意义的帮助。编辑您的问题并添加您的代码。在 Google 上搜索 Node.js 中的购物车设置示例。尝试将范围缩小到您遇到的特定问题或问题

标签: mysql node.js


【解决方案1】:

这是我已经拥有的一些内容:我将产品页面和信息存储在 MySQL 数据库中,该数据库托管在 gearhost 上。我也有用户登录页面。我只想知道如何将产品添加到购物车以及如何制作购物车页面、从购物车中删除、结帐等。

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

});

【讨论】:

    猜你喜欢
    • 2020-08-05
    • 2020-09-15
    • 1970-01-01
    • 2018-08-14
    • 2012-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多