1

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');
1
  • you have to create rest api for it and call from you react app using ajax and post your data there and in nodejs you have collect that data and insert into db Commented Mar 30, 2017 at 6:15

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

My react app is Login.js and my mysql table is "login" with field id, Email, Password. Connection file is dbConnection.js .. but still not working.
` app.post('/Login', function(req, res) { var post = { id: req.body.id, Email: req.body.Email, Password: req.body.Password }; console.log(req.body.Email); connection.query('INSERT INTO login VALUES ?', post, function(err, result) { // send response here res.json({msg:'success'}); }); app.listen(8080); console.log('App listening at port:8080'); });`
I think some setup issue occurring... let see.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.