I am learning node.js and I have managed to save data into mysql with form submit. The code looks like this:
app.post('/auth', function(request, response) {
let date = request.body.date;
let user = request.body.user;
let email = request.body.email;
connection.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var sql = "INSERT INTO demotable (date, user, email) VALUES (?,?,?)";
connection.query(sql, [date, user, email], function (err, result) {
response.end();
});
});
});
This works and the data is added to the table, but because I use input submit it takes me to a new page (/auth) afterwards. I need to update the database without updating or refreshing the whole page, meaning I cant use submit form. What is the best way to accomplish this instead?