I want to add a worker and then his id and name go to another table to work with
this doesnt work I tried it
router.post('/add_employee', (req, res) => {
// Insert into puntoretuji table
const sql = "INSERT INTO puntoretuji (name, salary, role) VALUES (?)";
const values = [req.body.name, req.body.salary, req.body.role];
con.query(sql, [values], (err, result) => {
if (err) return res.json({ Status: false, Error: "Query Error" });
return res.json({ Status: true});
});
}
);
router.post('/worker_id', (req, res) => {
const query = `SELECT MAX(id) AS max_id FROM puntoretuji`;
const values = [req.body.id]
const result = con.query(query, values)
const maxId = result[0].max_id;
// Insert into worker_data table
const insertWorkerDataQuery = "INSERT INTO worker_data (worker_id, name) VALUES (?)";
const workerDataValues = [maxId, req.body.name]; // Assuming current date for 'date'
con.query(insertWorkerDataQuery, workerDataValues);
}