Abdul Suadik Mohammed Abdul Suadik Mohammed - 1 year ago 202
Ajax Question

Inserting records into MySQL with node.js

Fetching records from a form with ajax to insert into mysql with node.js but only the first column works. The rest of the columns do not insert. Below is my code. What am I doing wrong? Thanks


$(document).ready(function (e) {
$("#new-user-form").on('submit',(function(e) {
var data = {};
data.title = $('#title').val();
data.fname = $('#fname').val();
data.mname = $('#mname').val();
data.lname = $('#lname').val();
data.mdname = $('#mdname').val();
//toastr.success('Page Loaded!');
url: "/new-user",
type: "POST",
data: data,
dataType: 'application/json',
cache: false,
success: function(data)


var express = require('express'),
router = express.Router(),
db = require('./../db');

router.post('/', function (req,res,next) {
var title = req.body.title;
var first_name = req.body.fname;
var middle_name = req.body.mname;
var last_name = req.body.lname;
var maiden_name = req.body.mdname;

Answer Source

Do you use https://github.com/felixge/node-mysql?

Try pass the object as one:

db.insert({first_name:first_name, last_name:last_name})

Insted of

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download