You are on page 1of 7

WEB TECH FAT

Nishant Mishra
20BIT0148
1. Design your own responsive web form to enter the details of Movie Ticket
Booking and inserted into the database by server using NODEJS and
MongoDB.

·         The HTML Form includes the following components:

Person Name, Movie Name (Dropdown list), Date, Show timing (Options of
Morning, Afternoon, Evening), Number of tickets, and Buttons to Booking and
Availability. [10]

·         Check the availability in the database, display the status at client-side
[15]

·         If tickets are available on particular slot, then book the tickets. [15]

·         Display every status message at server-side.[5]

·         Display all the documents after insertion at back-end.[5]

CODE:-

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>20BIT0148</title>
</head>
<body>
<section>
<h4>20BIT0148 Nishant Mishra</h4>
<h1>CHECK AVAILABILITY</h1>
<form method="post" action="/availability_0148">
<div>
<label for="movie">Select Movie Name : </label>
<select name="movie" size="1">
<option value="superman">Superman</option>
<option value="x-men">X-Men</option>
<option value="johnwick">JohnWick</option>
</select>
<br><br>
<input type="date" name="date" placeholder="Date"><br><br>
<label for="timings">Select Show Timings : </label>
<select name="timings" size="1">
<option value="morning">morning</option>
<option value="Evening">Evening</option>
<option value="Afternoon">Afternoon</option>
</select><br><br>
<input type="number" name="tickets" value="tickets"
placeholder="Number of Tickets"><br><br>
</div>
<br>
<input type="submit" value="Availability" class="btn">
</form>
<h1>BOOK TICKETS</h1>
<form method="post" action="/book_0148">
<div>
<input type="text" name="p_name" placeholder="Person
Name"><br><br>
<label for="movie">Select Movie Name : </label>
<select name="movie" size="1">
<option value="supermen">Supermen</option>
<option value="xmen">X-men</option>
<option value="johnwick">JohnWick</option>
</select>
<br><br>
<input type="date" name="date" placeholder="Date"><br><br>
<label for="timings">Select Show Timings : </label>
<select name="timings" size="1">
<option value="Morning">Morning</option>
<option value="Evening">Evening</option>
<option value="Afternoon">Afternoon</option>
</select><br><br>
<input type="number" name="tickets" value="tickets"
placeholder="Number of Tickets"><br><br>

</div>
<input type="submit" value="Book Tickets" class="btn">
</form>

</section>

MONGO DB:-
const express = require("express");
const app=express();
const path = require('path');
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

const port=process.env.PORT || 3000;

const mongoose=require("mongoose");
const { text } = require("body-parser");
mongoose.Promise = global.Promise;
mongoose.connect("mongodb://localhost:27017/Nishant_DB",{
useNewUrlParser:true,
useUnifiedTopology:true,
}).then(()=>{
console.log("Connection successful !");
}).catch((e)=>{
console.log("No Connection !!!",e);
});
function chk_avail(ticket)
{
var cap=5;
if(ticket<cap)
return "TICKETS ARE AVAILABLE . BOOK YOUR TICKETS NOW !";
else
return "TICKETS ARE UNAVAILABLE . CHOOSE ANOTHER SLOT !";
}
var MovieSchema2 = new mongoose.Schema({
p_name : String,
movie : String,
date : Date,
timings : String,
tickets : Number,
});
var MovieSchema1 = new mongoose.Schema({
movie : String,
date : Date,
timings : String,
tickets : Number,
});
var Avail_0148 = mongoose.model("avail_0148", MovieSchema1);
app.post("/availability_0148", (req, res) => {
var data=req.body;
var myData1 = new Avail_0148(req.body);
console.log(myData1);
myData1.save()
.then(item => {
res.send(chk_avail(data.tickets));
})
.catch(err => {
res.status(400).send("Unable to save to database");
});
});
var Book_0148 = mongoose.model("book_0148", MovieSchema2);
app.post("/book_0148", (req, res) => {
var data=req.body;
var myData2 = new Book_0148(req.body);
console.log(myData2);
myData2.save()
.then(item => {
res.send("YAY ! YOUR TICKETS HAVE BEEN BOOKED ! ENJOY");
})
.catch(err => {
res.status(400).send("Unable to save to database");
});
});
const static_path=path.join(__dirname,"../FAT_0148");
app.use(express.static(static_path));
app.listen(port,()=>{
console.log('Server is running at port numbers '+port);
})

You might also like