I just write two similar code like these, but only material can run and the order has the error "[ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client" when I submit the form
order.js
pool.getConnection(function(err,connection){
connection.query('SELECT customerid FROM order_table WHERE customerid =?', [customerid],function(err,rows){
if(err){
res.render('error',{
message:err.message,
error:err
});
}
/*
if(rows.length>=1){
res.render('operation/order',{warn:"You have already order!"});
}else{
*/
var cmd="INSERT INTO order_table(customerid,customerName,phonenumber,productid,amount,orderday,deadlineday) VALUES(?,?,?,?,?,?,?)";
connection.query(cmd,[customerid,customerName,phonenumber,productid,amount,orderday,deadlineday],function(err,result){
console.log(req.body);
if(err){
res.redirect('/order');
//return next();
}else{
res.render('operation/order_redirect');
}
});
//}
});
});
//callback(err, result);
connection.release();
});
module.exports=router;