How to rewrite the route URL when need to DELETE rows in a different table on particular page?
Below is the code for router module.
For the patient page has been set as home page(URL: "/") and doctor page has been set with URL: "/doctor".
Once I try to delete at doctor table then program doesn't delete on the doctor table but suddenly navigate back to patient page without delete anything.
Just wondering how to delete in doctor table with still staying on the doctor page after deletion. Meanwhile, when delete on the patient page, it still works correctly.
router.get('/doctor/:doctor_id', userController.deleteDoctorByID)
router.get('/:id', userController.deletePatientByID)
And below is the code from the Controller folder
// Delete Patient Info
exports.deletePatientByID = (req, res) => {
// Delete a record
// User the connection
connection.query('DELETE FROM patient WHERE id = ?', [req.params.id], (err, rows) => {
if (!err) {
res.redirect('/');
} else {
console.log(err);
}
console.log('Deleted Patient info')
});
}
// Delete doctor info
exports.deleteDoctorByID = (req, res) => {
// Delete a record
// User the connection
connection.query('DELETE FROM doctor_table WHERE doctor_id = ?', [req.params.doctor_id], (err, rows) => {
if (!err) {
res.redirect('/doctor');
} else {
console.log(err);
}
console.log('Deleted Doctor Info')
});
}
Also below is a part of my app.js for routes only.
const routes = require('./server/routes/connection');
app.use('/', routes);