How am I working with nodejs, mysql, forEach trying to save the email in my DB with a unique id, using the textarea tag, based on this question
Insert multiple email to mysql using single textarea
For-each over an array in JavaScript
javascript split on non-alphanumeric an keep delemiters at start
<form class="" action="/registration/instudent/{{id_school}}/{{mat}}/{{grade}}" method="post">
<textarea name="email" ></textarea>
<button class="btn btn-lg">Save</button>
</form>
Using the example in PHP base, in my example.js file I have this code, try to save all three variables.
router.post('/instudent/:id_school/:mat/:grade', isLoggedIn, async (req,res) => {
const { id_school, mat, grade } = req.params;
const { email } = req.body;
var uStudent = {
id_school,
mat,
grade,
email
}
Object.keys(uStudent).forEach(function (key){
console.log(uStudent[key]);
db.query('INSERT INTO date set ?', uStudent);
});
//res.redirect('/');
});
When saving to my database, incorrectly insert the texts. In my database it inserts me in this way.
Any guide to see what I am doing wrong and that every email in the textarea tag gets a unique id?