-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddadvance_q.js
38 lines (31 loc) · 987 Bytes
/
addadvance_q.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const express = require('express');
const router = express.Router();
const db = require('./db.js');
router.post('/', (req, res) => {
const { post_id, aq_id, aq_content } = req.body;
if (aq_id === null){
res.send('No advance question')
}
else
{
for (let i = 0; i < aq_id.length; i++) {
const currentAqId = aq_id[i];
const currentAqContent = aq_content[i];
const sql = `
INSERT INTO advance_q (post_id, aq_id, aq_content)
VALUES (?, ?, ?)
`;
const values = [post_id, currentAqId, currentAqContent];
db.query(sql, values, (err, results) => {
if (err) {
console.error('Error querying database: ' + err.stack);
res.status(500).send('Internal Server Error');
return;
}
console.log(currentAqId, 'advance question added successfully:', currentAqContent);
});
}
}
res.send('advance question added successfully');
});
module.exports = router;