Skip to content

Commit

Permalink
Day 6, 7, 8, 9 Added
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul-Bhati committed Sep 29, 2022
1 parent 9796f79 commit dc75478
Show file tree
Hide file tree
Showing 26 changed files with 308 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Day 5/view/demo.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
html
head
title Demo
body
h1 Pug File
table
tr
td 1
td rahul
td 78
tr
td 2
td ajay
td 79
tr
td=ename
td=salary
td=mobile

h1 #{ename}
table
tr
td=exp[0]
td=exp[1]
Binary file added Day 6/Fdlld-IX0AAfMSF.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Day 6/Fdlld-JWQAEJgWJ.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Day 6/Fdlld-KWIAAc0C-.jfif
Binary file not shown.
Binary file added Day 6/Fdlld-NXEAAvEZd.jfif
Binary file not shown.
15 changes: 15 additions & 0 deletions Day 6/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Day 6 (Adding Static Files)

const express = require("express");
const app = express();

app.set("view engine", "pug");
app.set("views", "./view");

app.use(express.static('public'));

app.get("/",function(request,response){
response.render("demo2");
});

app.listen(5000);
4 changes: 4 additions & 0 deletions Day 6/public/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
h1{
color: red;
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
}
Binary file added Day 6/public/images/bg2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Day 6/view/demo2.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
html
head
title Static File
link(href="/css/style.css" rel="stylesheet")
body
h1 This Demo File.
img(src="/images/bg2.jpg")
Binary file added Day 7/Screenshot (571).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Day 7/Screenshot (572).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Day 7/Screenshot (573).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions Day 7/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Day 7 (Retrive Data from Form using POST and GET Method)

const express = require("express");
const app = express();
// use body parse for get data by post method
const bodyParser = require("body-parser");
app.set("view engine", "pug");
app.set("views", "./view");
app.use(bodyParser.json()); // for post method bcs post me data direct json k formet m hota h
// for get/post method use urlencoded to encode data that we get from url
app.use(bodyParser.urlencoded({extended:true}));
app.get("/", function (request, response) {
response.render("Lec8"); // not retrive
});

app.get("/submit",function(request,response){
// response.send(request.query); // to get GET METHOD data use request.query
// response.send(JSON.stringify(request.query)); // to convert get data in string
console.log(request.query.roll);
var student = JSON.parse(JSON.stringify(request.query));
response.render("Lec8",{stud:student});
});
app.post("/submit", function (request, response) {
// response.send("Record not found");
response.send(request.body); // post m data json object hi hota h
console.log(request.body);
console.log(request.body.roll+" "+request.body.sname+" "+request.body.avg);
});

app.listen(5000);
59 changes: 59 additions & 0 deletions Day 7/view/Lec8.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
doctype html
head
title Bootstrap Example
meta(charset='utf-8')
meta(name='viewport' content='width=device-width, initial-scale=1')
link(rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css')
script(src='https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js')
script(src='https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js')
script(src='https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js')
style
include ./style.css
.container
.row
.col-sm-3
.col-sm-6
//- form(method='post' action='/submit')
label.form-label Roll No.
br
input.form-control(type='text' name='roll')
br
label.form-label Name
br
input.form-control(type='text' name='sname')
br
label.form-label Avg
br
input.form-control(type='text' name='avg')
br
input.btn.btn-danger(type='submit' name='submit' value='submit')
br
if(stud)
h3 #{stud.roll}
h3 #{stud.sname}
h3 #{stud.avg}
form(method='post' action='/submit')
label.form-label Roll No.
br
input.form-control(type='text' name='sn')
br
label.form-label Name
br
input.form-control(type='text' name='sname')
br
label.form-label Avg
br
input.form-control(type='text' name='avg')
br
label.form-label Gender
br
input(type='radio' value='Male')
| Male
input(type='radio' value='Female')
| Female
br
input.btn.btn-danger(type='submit' name='submit' value='submit')
br


Binary file added Day 8/Screenshot (575).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Day 8/Screenshot (576).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Day 8/Screenshot (577).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions Day 8/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Day 8 (Database Connectivity)
const express = require("express");
const mysql = require("mysql");
const app = express();
const bodyParser = require("body-parser");
const {UCS2_GENERAL_MYSQL500_CI,} = require("mysql/lib/protocol/constants/charsets");
app.set("view engine", "pug");
app.set("views", "./view");

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/", function (request, response) {
response.render("Lec9");
});
app.post("/submit", function (request, response) {
var conn = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "cet",
});
conn.connect(function (err) {
if (err) throw err;
conn.query(
"insert into student values("+request.body.roll+",'"+request.body.sname+"',"+request.body.avg+")",function (err, result) {
if (err) console.log("Try Again");
else {
// console.log("Record Inserted");
response.redirect("/record");
}
}
);
});
conn.end;
});

app.listen(5000);
34 changes: 34 additions & 0 deletions Day 8/view/Lec9.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
doctype html
head
title Bootstrap Example
meta(charset='utf-8')
meta(name='viewport' content='width=device-width, initial-scale=1')
link(rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css')
script(src='https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js')
script(src='https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js')
script(src='https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js')
style
include ./style.css
.container
.row
.col-sm-3
.col-sm-6
form(method='post' action='/submit')
label.form-label Roll No.
br
input.form-control(type='text' name='roll')
br
label.form-label Name
br
input.form-control(type='text' name='sname')
br
label.form-label Avg
br
input.form-control(type='text' name='avg')
br
input.btn.btn-danger(type='submit' name='submit' value='submit')
br
if(stud)
h3 #{stud.roll}
h3 #{stud.sname}
h3 #{stud.avg}
4 changes: 4 additions & 0 deletions Day 8/view/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
p{
font-size: medium;
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
}
Binary file added Day 9/Screenshot (578).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Day 9/Screenshot (579).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Day 9/Screenshot (580).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions Day 9/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Day 9 (Data Display after passing to pug file)
const express = require("express");
const mysql = require("mysql");
const app = express();
const bodyParser = require("body-parser");
const {UCS2_GENERAL_MYSQL500_CI,} = require("mysql/lib/protocol/constants/charsets");
app.set("view engine", "pug");
app.set("views", "./view");

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/", function (request, response) {
response.render("Lec9");
});
app.post("/submit", function (request, response) {
var conn = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "cet",
});
conn.connect(function (err) {
if (err) throw err;
conn.query(
"insert into student values("+request.body.roll+",'"+request.body.sname+"',"+request.body.avg+")",function (err, result) {
if (err) console.log("Try Again");
else {
// console.log("Record Inserted");
response.redirect("/record");
}
}
);
});
conn.end;
});
app.get("/record", function (request, response) {
var conn = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "cet",
});
conn.connect(function (err) {
if (err) throw err;
conn.query("select * from student", function (err, result) {
if (err) console.log("Try Again");
else {
response.render("Day9", { stud: result });
}
});
});
conn.end;
});


app.listen(5000);
34 changes: 34 additions & 0 deletions Day 9/view/Lec9.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
doctype html
head
title Bootstrap Example
meta(charset='utf-8')
meta(name='viewport' content='width=device-width, initial-scale=1')
link(rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css')
script(src='https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js')
script(src='https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js')
script(src='https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js')
style
include ./style.css
.container
.row
.col-sm-3
.col-sm-6
form(method='post' action='/submit')
label.form-label Roll No.
br
input.form-control(type='text' name='roll')
br
label.form-label Name
br
input.form-control(type='text' name='sname')
br
label.form-label Avg
br
input.form-control(type='text' name='avg')
br
input.btn.btn-danger(type='submit' name='submit' value='submit')
br
if(stud)
h3 #{stud.roll}
h3 #{stud.sname}
h3 #{stud.avg}
4 changes: 4 additions & 0 deletions Day 9/view/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
p{
font-size: medium;
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
}

0 comments on commit dc75478

Please sign in to comment.