Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mysql=require('mysql');
- var http=require('http');
- var async = require('async');
- var uuid = require('node-uuid');
- var path=require('path');
- var express=require('express');
- var app=express();
- var bodyparser=require('body-parser');
- app.use(bodyparser.json());
- app.use(bodyparser.urlencoded({extended: true}));
- var myconnection = mysql.createConnection({
- host : "localhost",
- user : "root",
- password : "",
- database : "siva"
- });
- app.use(express.static(__dirname + ""));
- var uqid= uuid.v1();
- // var tt=1;
- var status="active";
- app.post("/insert",function(req,res){
- // console.log(req.body.table.fields | mysum);
- /* TODO: Now just check that your drive function is correct, SQL is correct and whether what arguements passed to SQL callback is correct */
- myconnection.query('Insert into cate_tbl (cat_id,cat_name,cat_desc,cat_view_count,cat_status) VALUES ("'+uqid+'","'+req.body.cat_name+'","'+req.body.cat_desc+'","'+req.body.tot_count+'","'+status+'")',function(err, results, fields) {
- //if (err) throw err;
- if (err) {console.log("DB Error"+err); res.send("add failed"+err);}
- else
- async.each(req.body.fields, function(eachItem, callback) {
- console.log(eachItem.result1);
- myconnection.query('Insert into cate_item (cat_it_name,cat_pid,cat_it_count,cat_it_desc,address,cat_it_status) VALUES ("'+eachItem.item_name+'","'+uqid+'","'+eachItem.item_count+'","'+eachItem.item_desc+'","'+eachItem.result1+'","'+status+'")',function(err, results, fields) {
- if (err) {
- console.log("DB Error"+err);
- console.log(eachItem.result1);
- } else
- callback();
- });
- }, function(err, resp) {
- if(err) {
- console.log("DB error");
- } else {
- res.send("add success");
- }
- })
- });
- });
- app.get('/',function(req,res){
- res.sendfile("index.html");
- });
- app.listen(3000,function(){
- console.log("It's Started on PORT 3000");
- })
Add Comment
Please, Sign In to add comment