-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserinfo.js
44 lines (40 loc) · 1.27 KB
/
Userinfo.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
const express = require('express');
const bodyParser = require('body-parser');
const mysql = require('mysql');
require('dotenv').config();
var app = express();
app.use(bodyParser.urlencoded({extended:true}))
var sql = mysql.createConnection({
host:'localhost',
database:'Collagedata',
user:"root",
password:process.env.PASS
});
app.get('/',(req,res) => {
res.sendFile(__dirname+"/Userinfo.html");
});
app.post("/Userinfo",(req,res) => {
let {textid,textname,textpassword,textcpassword,textemail,textphone} = req.body;
if (!textid || !textname || !textpassword || !textcpassword || !textemail || !textphone) {
res.write("Please Enter all fields");
res.end();
}else if (textpassword!==textcpassword) {
res.write("password doesn't match");
res.end();
}
else {
sql.connect((err) => {
if(err) res.write(err.toString());
console.log("connected");
let q ="insert into Registration values('"+textid+"','"+textname+"','"+textpassword+"','"+textcpassword+"','"+textemail+"','"+textphone+"')";
sql.query(q,(err) => {
if(err) res.write(err.toString());
console.log("data saved");
res.write("data saved");
res.end();
})
});
}
});
app.listen(3000);
console.log("app running 3000");