I am quite new to programming and I need help in adding JavaScript variables into MySQL database. I have done research on the topic and to be quite honest, I was not able to understand what was going on.
Here is a bit of code that I am using. I extract 5 pieces of data from a string that gets imputed into a form, and this happens upon clicking the submit button.
case "individual":
    var partNumber = scanInput.substr(6, 8);
    var posOfQ1 = scanInput.indexOf("Q");
    var posOf1JUN = scanInput.indexOf("1JUN");
    //Quantity of the pack
    var total = scanInput.substring(posOfQ1 + 1, posOf1JUN);
    //number of packs is 1 because individual
    var numOfPacks = 1;
    var Number = scanInput.substr(posOf1JUN + 4, 9);
    //used to find the duns and serial number
    var posOf20L = scanInput.indexOf("20L");
    var posOf21L = scanInput.indexOf("21L");
    if (posOf21L == -1 || posOf20L < posOf21L){
      var serialNumber = scanInput.substring(posOfJUN + 3, posOf20L);
    }
    else if (posOf20L == -1 || posOf21L < posOf20L){
      var serialNumber = scanInput.substring(posOfJUN + 3, posOf21L);
    }
The 5 variables are partNumber, total, numOfPacks, Number, and serialNumber. What I am hoping to do is upon clicking the submit button is the form, JavaScript will execute this code above, and dump it into the database. How would I go about doing that?
I know that to establish a connection with SQL, the code looks something like this:
     var connection = new ActiveXObject("ADODB.Connection") ;
     var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB";
     connection.Open(connectionstring);
But I don't know what to put into the "Data Source" part and "Initial Catalog" part, and I don't know how to input things into the database from here.
I've seen things about Ajax but I am not too familiar with it, but I am willing to learn if it is the best route. Thanks for your help.
 
     
     
     
     
    