POST mysql

PHOTO EMBED

Wed Jun 01 2022 20:22:46 GMT+0000 (Coordinated Universal Time)

Saved by @zaccamp #javascript

// Create a candidate
app.post('/api/candidate', ({ body }, res) => {
  const errors = inputCheck(body, 'first_name', 'last_name', 'industry_connected');
  if (errors) {
    res.status(400).json({ error: errors });
    return;
  }

const sql = `INSERT INTO candidates (first_name, last_name, industry_connected)
  VALUES (?,?,?)`;
const params = [body.first_name, body.last_name, body.industry_connected];

db.query(sql, params, (err, result) => {
  if (err) {
    res.status(400).json({ error: err.message });
    return;
  }
  res.json({
    message: 'success',
    data: body
  });
});
});
content_copyCOPY

https://courses.bootcampspot.com/courses/972/pages/12-dot-2-7-create-the-post-route?module_item_id