-
Notifications
You must be signed in to change notification settings - Fork 0
/
confData.js
41 lines (39 loc) · 1.48 KB
/
confData.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
39
40
41
const http = require('http');
const url = require('url');
const mysql = require('mysql');
const qs = require('querystring');
const con = mysql.createConnection({
host: "localhost:3306",
user: "workbench",
password: "ninguna",
database: "fullstack"
});
http.createServer((req, res) => {
if (req.method === 'POST') {
let body = '';
req.on('data', (chunk) => {
body += chunk.toString();
});
req.on('end', () => {
let post = qs.parse(body);
if (req.url === '/confData.js') {
// Update user profile
let sql = "UPDATE users SET name = ?, email = ?, password = ? WHERE id = ?";
let values = [post.name, post.email, post.password, post.id]; // Assuming you also send user id
con.query(sql, values, (err, result) => {
if (err) throw err;
console.log("Number of records updated: " + result.affectedRows);
});
} else if (req.url === '/confDelete.js') {
// Delete account
let sql = "DELETE FROM users WHERE id = ?";
let values = [post.id]; // Assuming you also send user id
con.query(sql, values, (err, result) => {
if (err) throw err;
console.log("Number of records deleted: " + result.affectedRows);
});
}
res.end('ok');
});
}
}).listen(3306);