-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.js
102 lines (63 loc) · 2.59 KB
/
form.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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){
// fs.readFile("form.html",function(err,content)
// { res.end(content)};
// res.writeHead(200, {
// 'Content-Type': 'text/html'});
// res.write(req.cookies.username);
// fs.readFile("form.html",function(err,content)
// {
// res.end(content);
// });
console.log("In form");
res.sendFile('/form.html',{root:__dirname});
});
router.post('/',function(req,res){
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");
console.log(result);
res.writeHead(200, {
'Content-Type': 'text/html'});
res.write(req.cookies.username);
res.write("<form action='/form' 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>');
});
connection.end();
});
module.exports=router;