i have a logical error idk where exactly, i think my query is wrong, i have this code (nodejs):
router.post('/compteCon', (req, res)=>{
console.log('CONNECTION OF AN ACCOUNT');
const email = req.body.email;
const MotPasse = req.body.MotPasse;
console.log(email ' ' MotPasse)
const sql = 'select * from compte where (compte.email = \"' email '\" and \"' MotPasse '\"=compte.MotPasse1)'
getConn().query(sql,(err, results)=>{
if(err){
console.log('failed Connect to account : ', err)
res.sendStatus(500)
return
}
if(results[0] == null){
console.log("Your Email or Password is wrong");
res.end();
}else{
console.log(results[0]);
res.end();
}
})
res.redirect('next.html')
res.end();
})
the result shown when i submit the POST form connection with an account exist in my database is:
server running port is 3000
CONNECTION OF AN ACCOUNT
undefined undefined
::1 - - [30/Aug/2022:14:06:01 0000] "POST /compteCon HTTP/1.1" 302 62 "http://localhost:3000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"
Your Email or Password is wrong
look at the last sentence result!!
i have on index.html this button (bootstrap styling!)
<div >
<button type="submit" id="submitBtn">Login</button>
</div>
CodePudding user response:
i remove this div:
<div ></div>
and now only:
<button type="submit" id="submitBtn">Login</button>
CodePudding user response:
It seems like nothings actually being passed as shown when the console says: undefined undefined. So it most likely isn't your query rather the fact that it has nothing to actually work with. Maybe, the frontend isn't passing the required data to the backend, just keep trying to debug, but this should lead you in the right direction.