2020-12-31

Cannot POST /updatedata

1.I am trying to modify my data in mysql database but getting error

  1. I am able to add the data but unable to modify the data.

  2. I have created a seperate tab in main page as modify. What changes needs to be done?


**var mysql = require('mysql');
var express = require('express');
var bodyParser = require('body-parser');
var connection = mysql.createConnection({
    host     : 'localhost',
    user     : 'root',
    password : '',
    database : 'mr',
    port: '3308',
});
var app = express();
app.use(bodyParser.urlencoded({extended : false}));
app.use(bodyParser.json());
app.get('/', function(request,response){
    response.sendFile(__dirname + '/home.html');
});
app.get('/update', function(request, response){
    response.sendFile(__dirname + '/modify.html');
});
app.put('/updatedata',function(req,res){
    
    connection.query('update hp set Name=?,Address=?,Country=?,Phone=? where Id=?',[req.body.Name,req.body.Address,req.body.Country,req.body.Phone,req.body.Id],function(error,results,fields){
        if(err) throw err;
        console.log("Record updated");
        res.redirect('/home');
    });
});
app.get('/home', function(request, response) {
    
    response.sendFile(__dirname + '/home.html');
});
app.listen(5000);
console.log('Server Started');**


from Recent Questions - Stack Overflow https://ift.tt/3rJPqPF
https://ift.tt/eA8V8J

No comments:

Post a Comment