Any idea on how to solve the issue? Here is the code, the console.log(custID) shows the correct value, but the value of custID did not get passed to the second SQL
Thanks
app.post("/api/Cust", (req, rsp) => {
const func = req.body.func;
const custName = req.body.custName;
const IC = req.body.IC;
const gender = req.body.gender;
const custDOB = req.body.custDOB;
const addr1 = req.body.addr1;
const addr2 = req.body.addr2;
const addr3 = req.body.addr3;
const country = req.body.country;
const email = req.body.email;
const hp = req.body.hp;
var custID=''
console.log("inside db code");
console.log(req.body.func);
if (func==="new") {
const IDStmt = "select concat('TP-',lpad(nextcust,6,'0')) as nextcust from autoref;";
db.query( IDStmt, ( err, result) => {
nextcustList = result;
console.log("inside get start");
console.log(result);
result.map( e => { custID = e.nextcust });
console.log(custID);
console.log("inside get end");
})
const sqlStmt = "insert into cust_master (custID, custName, IC, MaleFemale, Birthday, Street, BLK, City, Country, Email, HP, register_date) values ( ?,?,?,?,?,?,?,?,?,?,?,curdate() );";
db.query( sqlStmt, [custID, custName, IC, gender, custDOB, addr1, addr2, addr3, country, email, hp], ( err, result) => {
console.log(err);
})
const updStmt = "update autoref set nextcust = nextcust + 1;"
db.query( updStmt, ( err, result) => {
console.log(err);
})
}
})