Sending data in a html form to mysql data base using express results in undefined database columns
You're using express.json()
but your form data is not in JSON format.
You can install express-formidable
with npm in your app folder
Then you need to create the middleware using it, like so:
// in app.js
const formidableMiddleware = require('express-formidable');
//...
// Note that req.fields will be instead of req.body due to middleware
// used to handle json, forms, and uploading files
app.use(formidableMiddleware(
{
encoding: 'utf-8',
// means multi files (array of files) in one request
multiples: true,
}
));
You will need to replace app.use(express.json());
with above snippet
You can also check an example from ExpressJS repo on github for multipart forms