Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.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 无法使用getElementById将表单数据传递给SQLite_Javascript_Sqlite - Fatal编程技术网

Javascript 无法使用getElementById将表单数据传递给SQLite

Javascript 无法使用getElementById将表单数据传递给SQLite,javascript,sqlite,Javascript,Sqlite,我无法使用getElementById将数据从HTML表单传递到SQLite 这是一段非常简单的代码,用于学习如何将SQLite用于永久存储 我的代码: <!DOCTYPE HTML> <html> <head> <script type="text/javascript"> var db = openDatabase('sightings', '1.0', 'Test DB', 2 * 1024 * 1024); var msg; funct

我无法使用getElementById将数据从HTML表单传递到SQLite

这是一段非常简单的代码,用于学习如何将SQLite用于永久存储

我的代码:

<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
var db = openDatabase('sightings', '1.0', 'Test DB', 2 * 1024 * 1024);
var msg;


function InsertValues() {
var mydata = document.getElementById("CommonName").value;
db.transaction(function (tx) {      
  tx.executeSql('CREATE TABLE IF NOT EXISTS Sights (CommonName CHAR(17), location CHAR(32), datte CHAR(10), Observations CHAR(90))');
  tx.executeSql('INSERT INTO Sights (CommonName,location,datte,Observations) VALUES (mydata,"loobo","loobo","loobo")');
  msg = '<p>Log message created and row inserted.</p>';
  document.querySelector('#status').innerHTML =  msg;
});
}


function myfunction2() {
db.transaction(function (tx) {
  tx.executeSql('SELECT * FROM Sights', [], function (tx, results) {
   var len = results.rows.length, i;
   msg = "<p>Found rows: " + len + "</p>";
   document.querySelector('#status').innerHTML +=  msg;
   for (i = 0; i < len; i++){
     msg = "<p><b>" + results.rows.item(i).CommonName + "</b></p>";
     document.querySelector('#status').innerHTML +=  msg;
   }
 }, null);
});
}
</script>

</head>


<body>
<div class="observation">
  <h1></h1>
  <form action="#" method="post">
    <fieldset>
      <label for="name" >Common Name:</label>
      <input type="text" id="CommonName" placeholder=" Bird common Name" />
      <label for="name" >Location:</label>
      <input type="text" id="location" placeholder=" Where you see it" />
      <label for="email">Date</label>
      <input type="date" id="date" placeholder="mm/dd/yyy" /> 
      <label for="message">Observations:</label>
      <textarea id=" Observations" placeholder="What you see"></textarea>    
    <input type="submit" value="Register" onclick="InsertValues();">        
    </fieldset>
  </form>

</div>

 <script type="text/javascript">
            myfunction2();
 </script>
<div id="status" name="status">Status Message</div>

</body>
</html>

什么问题阻止了从HTML表单到SQLite的数据流?

要将代码中的字符串值转换成SQL语句,请使用参数:

tx.executeSql('INSERT INTO Sights (CommonName,location,datte,Observations) '+
              'VALUES (?, ?, ?, ?)',
              [mydata, 'loobo', 'loobo', 'loobo']);
可供受信任的调用者使用,仅指扩展和Firefox组件。API随时可能更改,并标记为fixit,需要技术审查。