Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to Execute Multiple Insert Queries in NodeJs Application?

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 801
    Answer it

    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");

 1 Answer(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: