-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
68 lines (48 loc) · 1.19 KB
/
server.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const express = require('express');
var mysql = require('mysql')
const app = express();
app.use(express.static('./'))
app.use(express.urlencoded({extended: false}))
app.set('view engine','pug')
app.get('/', (req,res)=>{
res.sendFile('landingpage.html', {root:__dirname});
})
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'covid resources'
})
connection.connect(function(err){
if (err) {
throw err;
}
console.log('Connected...');
})
app.post('/register',(req, res)=>{
console.log(req.body);
var sql="insert into donor_info values('"+req.body.name+"', '"+req.body.age+"', '"+req.body.bldgrp+"', "+req.body.recday+", '"+req.body.mobno+"')";
connection.query(sql,function(err){
if (err) {
throw err;
}
})
res.render('donate',{title:'Data saves',
message:'Data saved successfully.' })
})
app.get('/list', (req,res)=>{
connection.query("SELECT * FROM donor_info",(err,rows,fields)=>{
if (err) {
throw err;
}
res.render('list',{title:'Donor Details',
items : rows })
})
});
app.listen(3000,()=>{
console.log('Server is running on port 3000');
})
/*
/ -->res=this is working
/donate --> POST=success/fail
*/