我一直试图在数据库中添加一个表,但由于某种原因它不起作用。
这是有问题的代码

var db = openDatabase('movies', '1.0', 'movies database', 50 * 1024 * 1024);


$("#newplayers").submit(function (event) {
    event.preventDefault();
    //The two variables are called from the input of the player, denoting Company Name and Player Name.
    companyName = document.getElementById("companyname").value;
    playerName = document.getElementById("playername").value;
    db.transaction(function(tx) {
        tx.executeSql('CREATE TABLE userinfo (_id INTEGER PRIMARY KEY, player TEXT, company TEXT)');
        tx.executeSql('INSERT INTO userinfo (player,company) VAUES (?, ?)', [playerName,companyName]);
    });
    document.getElementById("company").innerHTML = companyName;
});

更让我困惑的是,在代码的其他地方,我完美地创建了一个表,并且使用看似相同的代码并没有带来相同的结果。

最佳答案

关于sql execute insert语句

tx.executeSql('INSERT INTO userinfo (player,company) VAUES (?, ?)', [playerName,companyName]);

您有"VAUES"(而不是值)

关于javascript - 无法在Web SQL数据库中创建新表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27714666/

10-12 00:04