Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mysql=require('mysql');
- var express=require('express');
- var bodyParser=require('bodyParser');
- var app= express();
- app.use (bodyParser.json());
- app.use (bodyParser.urlencoded({ extended: true }) );
- var server=app.listen(process.env.PORT||8000, function(err){
- if(err)throw err;
- console.log('Connected to port 8000');
- });
- var conn=mysql.createConnection({
- host: 'localhost',
- user: 'root',
- password: 'rootpass',
- database: 'mydb'
- });
- conn.connect(function(err){
- if(err)throw err;
- console.log('Connected');
- });
- /*
- conn.query ('CREATE DATABASE mydb', function(err, res){
- if(err)throw err;
- console.log(res);
- });
- conn.query('CREATE TABLE student\
- ( ID INT NOT NULL,\
- nume VARCHAR(20) NOT NULL,\
- prenume VARCHAR(20) NOT NULL,\
- facultate VARCHAR(20) NOT NULL,\
- oras VARCHAR(20) NOT NULL)',
- function(err, res){
- if(err) throw err;
- console.log(res);
- }
- );
- */
- app.get('/app.html',function(req,res){
- res.sendFile(__dirname + '/app.html');
- });
- app.port('/app',function(req,res){
- var arr= [[req.body.id, req.body.nume, req.body.prenume,
- req.body.facultate, req.body.oras]];
- conn.query('INSERT INTO student VALUES ?',[arr], function(err,result){
- if(err)throw err;
- console.log('Succes');
- });
- res.end();
- });
- conn.query('SELECT * FROM student',function(err,res){
- if(err)throw err;
- console.log(res);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement