-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js.save.1
95 lines (62 loc) · 2.57 KB
/
index.js.save.1
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var express = require('express');
var router = express.Router();
var mysql = require('mysql');
var cookieParser = require('cookie-parser');
var fs = require('fs');
const bodyParser = require('body-parser');
router.use(cookieParser());
router.get('/',function(req,res){
console.log('In index');
res.sendFile('/Flighty/index.html',{root:__dirname});
});
router.post('/',function(req,res){
console.log("I am in post");
// fs.readFile("/Flighty/index.html",function(err,content)
// { res.end(content);
//});
console.log(req.body);
var stpoint=req.body.startpoint;
var destpoint=req.body.destpoint;
var connection = mysql.createConnection({
host:'localhost',
user:'root',
password: 'vishal',
database: 'airline'
});
connection.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
var sql = "select * from flight where startpoint = ? and destpoint= ?";
connection.query(sql,[stpoint, destpoint], function (err, result) {
if (err) throw err;
console.log("1 record inserted");
var data=result;
console.log(result);
// res.writeHead(200, {
// 'Content-Type': 'text/html'});
//res.write("Hello");
// res.write(req.cookies.username);
//res.write("<form action='/index' method='post'><select name='startpoint'><option value='delhi'>Delhi</option><option value='chandigarh'>Chandigarh</option></select><select name='destpoint'><option value='delhi'>Delhi</option><option value= 'chandigarh'>Chandigarh</option></select><input type='submit' name='submit'></form> ");
//res.write('<table border=1px>');
//res.write('<tr><th>'+'Flightno'+'</th><th>'+'Flightname'+'</th><th>'+'Start Point'+'</th><th>'+'Destination Point'+'</th><th>'+'Arrival Time'+'</th><th>'+'Departure Time'+'</th><th>'+'Economic Fare'+'</th><th>'+'Business Fare'+'</th><th>'+'Register'+'</th></tr>');
//for(var i=0;i<result.length;i++)
//{
// res.write("<form action='/register' method='post'>");
// res.write("<tr><td><input type='text' name= 'flightno' style='setEditable:false;' value="+result[i].flightno+" readonly></td>");
// res.write('<td>'+result[i].flightname+'</td>');
// res.write('<td>'+result[i].startpoint+'</td>');
// res.write('<td>'+result[i].destpoint+'</td>');
// res.write('<td>'+result[i].arrivaltime+'</td>');
// res.write('<td>'+result[i].depttime+'</td>');
// res.write('<td>'+result[i].economicfare+'</td>');
// res.write('<td>'+result[i].businessfare+'</td>');
// res.write('<td>'+'<input type="submit" value="BookNow">'+'</td></tr>');
// res.write('</form>');
//}
//res.end('</table>');
response.render('')
});
connection.end();
});
module.exports =router;