-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
71 lines (62 loc) · 1.75 KB
/
app.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
69
70
71
var express = require('express');
var bodyParser =require('body-parser');
var app = express();
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "Girlboss06",
database: "formdb"
});
var urlencodedParser = bodyParser.urlencoded({ extended: false});
app.set('view engine', 'ejs');
app.get('/' , function(req,res){
res.render('index')
});
app.get('/contact' , function(req,res){
res.render('index')
});
app.get('/form', (req,res)=>{
con.query('select* from forms',(err,rows,feilds)=>{
if(!err)
res.send(rows);
else
console.log(err);
})
});
app.get('/form/:id', (req,res)=>{
con.query('select* from forms where fullname= ?', [req.params.id], (err,rows,feilds)=>{
if(!err)
res.send(rows);
else
console.log(err);
})
});
app.delete('/form/:id', (req,res)=>{
con.query('delete from forms where fullname= ?', [req.params.id], (err,rows,feilds)=>{
if(!err)
res.send('Deleted succesfully.');
else
console.log(err);
})
});
app.post('/contact' , urlencodedParser,function(req,res){
let name= req.body.name;
let department=req.body.department;
let email=req.body.email;
console.log(req.body);
console.log(req.body.name);
console.log(req.body.department);
console.log(req.body.email);
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var sql = "INSERT INTO forms(fullname, department,email) VALUES ('"+name+"','"+ department+"','"+ email+"')";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");
});
})
res.render('contact-success', {data: req.body});
});
app.listen(process.env.PORT);