简体   繁体   中英

How to save Signup form data in database(mysql) using reactjs and nodejs?

I have made signup form using Reactjs and want to be save emailid, password, name, address in my database(mysql) who user enter at time of signup.

I have made connection using mysql & working fine but unable to store data of signup form.

var express    = require("express");
var mysql      = require('mysql');
var connection = mysql.createConnection({
host     : 'localhost',
user     : 'root',
password : 'root',
database : 'myform'
});

var app = express();

connection.connect(function(err){
if(!err) {
    console.log("Database connection successful !!!");    
} else {
  console.log("Database connection failure !!!");    
}
});
app.listen(8080);
console.log('App listening at port:8080');

Try following

Nodejs

      var mysql = require('mysql');

      var connection = mysql.createConnection({
        host: 'cccc.net',
        user: 'xxxxx_usr',
        password: 'xxxxxxx',
        database: 'name of your database goes here …'
      });

     // api here 
     app.post('/addUser', function(req, res) {
      var post = {
        srcUserID: req.body.userSrcID,
        destUserID: req.body.userid,
        messageContent: req.body.txt,
        messageSendDate: req.body.sendDate
      };

      connection.query('INSERT INTO messages VALUES ?', post, function(err, result) {
        // send response here
        res.json({msg:'success'});
      });

    });

you can make change in parameters

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM