Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 值未从输入错误插入数据库:phonegap中未定义_Javascript_Sqlite_Cordova - Fatal编程技术网

Javascript 值未从输入错误插入数据库:phonegap中未定义

Javascript 值未从输入错误插入数据库:phonegap中未定义,javascript,sqlite,cordova,Javascript,Sqlite,Cordova,我对phonegap不熟悉。我创建了包含两个表的数据库。它显示了未定义的sql错误。我使用下面的代码创建了另一个表,并进行了少量修改。该表工作正常。但下面的代码不工作。我无法找到错误。其中有什么错误。请帮助 function insertVehicleData(tx) { var db=window.openDatabase("FuelDatabase","1.0","FuelData",200000); db.transaction(vehicleDB,errorVDB,suc

我对phonegap不熟悉。我创建了包含两个表的数据库。它显示了未定义的sql错误。我使用下面的代码创建了另一个表,并进行了少量修改。该表工作正常。但下面的代码不工作。我无法找到错误。其中有什么错误。请帮助

function insertVehicleData(tx)
{
    var db=window.openDatabase("FuelDatabase","1.0","FuelData",200000);
    db.transaction(vehicleDB,errorVDB,successVDB);
}

function vehicleDB(tx)
{
    tx.executeSql('CREATE TABLE IF NOT EXISTS  vehicledata (vhname TEXT, vmake   TEXT,vtype TEXT,currency TEXT)');

    var  vhname=document.getElementById('vhname').value;
    var vmake= document.getElementById('vmake').value;
    var  vtype=document.getElementById('vtype').value;
    var currency=document.getElementById('currency').value;

    tx.executeSql("INSERT INTO vehicledata (vhname,vmake,vtype,currency) VALUES ('"+ vhname +"','"+ vmake +"' , "+ vtype+", '"+ currency +"')");

 }

 function errorVDB(tx,error)
 {
     alert("error not saved:"+error);
 }

 function successVDB()
 {
     alert("your data saved");
 }

尝试替换此行:

tx.executeSql("INSERT INTO vehicledata (vhname,vmake,vtype,currency) VALUES ('"+ vhname +"','"+ vmake +"' , "+ vtype+", '"+ currency +"')");
tx.executeSql("INSERT INTO vehicledata (vhname,vmake,vtype,currency) VALUES (?,?,?,?)",[vhname,vmake,vtype,currency]);
这一行:

tx.executeSql("INSERT INTO vehicledata (vhname,vmake,vtype,currency) VALUES ('"+ vhname +"','"+ vmake +"' , "+ vtype+", '"+ currency +"')");
tx.executeSql("INSERT INTO vehicledata (vhname,vmake,vtype,currency) VALUES (?,?,?,?)",[vhname,vmake,vtype,currency]);
理由是,当插入值时,可能有需要转义的项,否则它们可能会“破坏”语句。这样做可以确保正确转义值