Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


NodeJs: Multiple insert queries

I am trying to perform an insert query, use the insertid of the row and then perform another insert query using the inert id. the first query is executing but the second query is not. please help. Below is my code:
var opdname = $("#opdname").val();
var opdsex = $("#opdsex").val();
var opdage = $("#opdage").val();
var opdaddress = $("#opdaddress").val();
var opdcity = $("#opdcity").val();
var opdstate = $("#opdstate").val();
var opdpin = $("#opdpin").val();
var opdcon = $("#opdcon").val();
var opdmail = $("#opdmail").val();
var opdpresfee = $("#opdpresfee").val();
var odate = new Date();
var opdmonth = odate.getMonth()+1;
var opdyear = odate.getFullYear();
var opdday = odate.getDate();
var opddate = opdday+"/"+opdmonth+"/"+opdyear;
var opdtime =;
var opdvisstatus = "Waiting";
var opdchargedes = "Prescription Fee";
var opdsyncstat = "no";
var opdid = "";
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'plasmadoc',
multipleStatements: true

    return console.log(err.stack);
 var postopd = {opdid:opdid, name: opdname, age: opdage, sex: opdsex, contact: opdcon, address: opdaddress, pin: opdpin, city: opdcity, state: opdstate, email: opdmail, date: opddate, syncstatus: opdsyncstat, opdtime: opdtime};

connection.query("INSERT INTO opdrec SET?", postopd, function(err, rows) {
console.log("An error ocurred performing the query.");
var insertid = rows.insertId;
var postvisit = {opdid: insertid, date: opddate, chargedes: opdchargedes, charge: opdpresfee, visitstatus: opdvisstatus, syncstatus: opdsyncstat, vistime: opdtime};
connection.query("INSERT INTO opdvisits SET?", postvisit, function(error, result){
alert("New OPD Record Added");


Sign In or Register to comment.