node.js - how to insert data into database in electron SQl as database And React as front end -


i new @ electron.

i trying build small app using electron. trying insert data taken front end.

i using sql has database , react front end can give suggestions.

how insert data? can 1 please give me solution it?

please me.

i tried this: index .html , need post data taken here. , in zipcode.js mysql code there.

index.html

<div>                     <form classname =" col-lg-12 form-horizontal" role="form" >                         <nav classname="navbar navbar-inverse navbar-fixed-top">                             <div classname = "container-fluid">                                 <div classname="navbar-header">                                     <div classname="col-lg-12 col-sm-12 col-xs-12">                                         <div classname ="row">                                             <div classname="col-lg-2 col-sm-2 col-xs-2">                                                 <button type="submit" id="btnsubmit" classname="btn btn-primary center-block">                                                     submit                                                 </button>                                             </div>                                             <div classname="col-lg-1 col-sm-1 col-xs-1">                                                 <button type="reset" classname="btn btn-danger center-block">                                                     cancel                                                 </button>                                             </div>                                         </div>                                     </div>                                 </div>                             </div>                         </nav>                         <br/><br/><br/>                         <div classname ="container">                             <div classname = "row">                                 <div classname = "row">                                     <div classname="col-lg-6 col-sm-6 col-xs-6">                                         <div classname="form-group">                                             <div classname="col-lg-1 col-sm-1">                                             </div>                                             <label classname="control-label col-lg-4 col-sm-4 col-xs-12" for="zipcode">zip code:</label>                                             <div classname="col-lg-6 col-sm-6 col-xs-12">                                                 <input type="number" classname="form-control" id="zipcode" ref = "zipcode" placeholder="zip code" required="true"/>                                             </div>                                             <div classname="col-lg-1 col-sm-1">                                             </div>                                         </div>                                     </div>                                     <div classname="col-lg-6 col-sm-6 col-xs-6">                                         <div classname="form-group">                                             <label classname="control-label col-lg-4 col-sm-4 col-xs-12" for="shortcode">short code:</label>                                             <div classname="col-lg-6 col-sm-6 col-xs-12">                                                 <input type="short code" classname="form-control" id="shortcode" ref = "shortcode" placeholder="short code" required="true"/>                                             </div>                                             <div classname="col-lg-2 col-sm-2">                                             </div>                                         </div>                                     </div>                                 </div>                                 <div  classname = "row">                                     <div classname="col-lg-6 col-sm-6 col-xs-6">                                         <div classname="form-group">                                             <div classname="col-lg-1 col-sm-1">                                             </div>                                             <label classname="control-label col-lg-4 col-sm-4 col-xs-12" for="city">city:</label>                                             <div classname="col-lg-6 col-sm-6 col-xs-12">                                                 <input type="city" classname="form-control" id="city" ref = "city" placeholder="city" required="true"/>                                             </div>                                             <div classname="col-lg-1 col-sm-1">                                             </div>                                         </div>                                     </div>                                     <div classname="col-lg-6 col-sm-6 col-xs-6">                                         <div classname="form-group">                                             <label classname="control-label col-lg-4 col-sm-4 col-xs-12" for="state">state:</label>                                             <div classname="col-lg-6 col-sm-6 col-xs-12">                                                 <input type="state" classname="form-control" id="state" ref = "state" placeholder="state" required="true"/>                                             </div>                                             <div classname="col-lg-2 col-sm-2">                                             </div>                                         </div>                                     </div>                                 </div>                                 <div classname = "row">                                     <div classname="col-lg-6 col-sm-6 col-xs-6">                                         <div classname="form-group">                                             <div classname="col-lg-1 col-sm-1">                                             </div>                                             <label classname="control-label col-lg-4 col-sm-4 col-xs-12" for="phoneareacode">phone area code:</label>                                             <div classname="col-lg-6 col-sm-6 col-xs-12">                                                 <input type="phoneareacode" classname="form-control" id="phoneareacode" ref = "phoneareacode" placeholder="phone area code" required="true"/>                                             </div>                                             <div classname="col-lg-1 col-sm-1">                                             </div>                                         </div>                                     </div>                                     <div classname="col-lg-6 col-sm-6 col-xs-6">                                     </div>                                 </div>                                 <div classname = "row">                                     <div classname="col-lg-6 col-sm-6 col-xs-6">                                         <div classname="form-group">                                             <div classname="col-lg-1 col-sm-1">                                             </div>                                             <label classname="control-label col-lg-4 col-sm-4 col-xs-12" for="taxcode">tax code:</label>                                             <div classname="col-lg-6 col-sm-6 col-xs-12">                                                 <input type="taxcode" classname="form-control" id="taxcode" ref = "taxcode" placeholder="tax code" required="true"/>                                             </div>                                             <div classname="col-lg-1 col-sm-1">                                             </div>                                         </div>                                     </div>                                     <div classname="col-lg-6 col-sm-6 col-xs-6">                                         <div classname="form-group">                                             <label classname="control-label col-lg-4 col-sm-4 col-xs-12" for="tax">%tax:</label>                                             <div classname="col-lg-6 col-sm-6 col-xs-12">                                                 <input type="number" classname="form-control" id="tax" ref = "tax" placeholder="tax" required="true"/>                                             </div>                                             <div classname="col-lg-2 col-sm-2">                                             </div>                                         </div>                                     </div>                                 </div>                             </div>                          </div>                     </form>                 </div> 

zipcode.js

window.onload = function() {  document.getelementbyid("btnsubmit").onclick = function () {     alert('submit button click');     var v1 = document.getelementbyid('zipcode').value;     var v2 = document.getelementbyid('shortcode').value;     var v3 = document.getelementbyid('city').value;     var v4 = document.getelementbyid('state').value;     var v5 = document.getelementbyid('phoneareacode').value;     var v6 = document.getelementbyid('taxcode').value;     var v7 = document.getelementbyid('tax').value;     //alert("zipcode:"+v1+" "+"shortcode:"+v2+" "+"city:"+v3)     //sql connection     //alert('after connection');     var connection = require('tedious').connection;      var config = {         username: 'xx',         password: 'xxxx',         server: 'xxxxxx', // can use 'localhost\\instance' connect named instance         database: 'xxxxx',         options: {             database: 'xxxxx'         },     }     alert("sql")     var connection = new connection(config);     connection.on('connect',function(err){         alert('hai')         if(err){             console.log(err)         }         executestatement();     });     request = require('tedious').request;     function executestatement(){         //alert(v1,v2,v3,v4,v5,v6,v7)         var request = new request("insert xxxxx values ("+v1+",'"+v2+"','"+v3+"','"+v4+"','"+v5+"','"+v6+"',"+v7+")",             function(err,result){                 console.log(request)                 if(err){                     console.log(err);                 }else{                     console.log(result)                 }             });         connection.execsql(request);     }     alert('completion')   } } 

tedious package connects using tds protocol , afiak not support mysql.

if using mysql, perhaps should try sequelize js or node-mysql.

update: based on comment, sounds need change order in things execute. can moving dependent code (the code execute after connection) end of connection callback function this...

var connection = new connection(config); connection.on('connect',function(err){     alert('hai')     if(err){         console.log(err)     }     else{       request = require('tedious').request;       function executestatement(){           //alert(v1,v2,v3,v4,v5,v6,v7)           var request = new request("insert xxxxx values ("+v1+",'"+v2+"','"+v3+"','"+v4+"','"+v5+"','"+v6+"',"+v7+")",               function(err,result){                   console.log(request)                   if(err){                       console.log(err);                   }else{                       console.log(result)                   }               });           connection.execsql(request);       }     }     alert('completion') }); 

also, may have missed semicolon, , have comma...

var config = {     username: 'xx',     password: 'xxxx',     server: 'xxxxxx', // can use 'localhost\\instance' connect named instance     database: 'xxxxx',     options: {         database: 'xxxxx'     }  // <-- no comma here };    // <-- add semicolon here     

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -