Insert data into Sqlite

Asked

Viewed 375 times

1

I’m learning to use Sqlite, but I’m not able to enter the data. Come on, I’m creating a simple space for the user to enter his name and password and a button to send the data in Sqlite. My html is below:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Banco de Dados Local</title>
        <script type="text/javascript" src="SQlite.js"></script>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <form class="login-box" onsubmit="save()">
            <h1>Login</h1>
            
            <div class="textbox">
                <i class="fa fa-user" ariahidden="true"></i>
                <input type="text" id="user" placeholder="Username" name="" value=""><br>
            </div>
            <div class="textbox">
                <i class="fa fa-lock" aria-hidden="true"></i>
                <input type="password" id="senha" placeholder="Password" name="" value=""><br>
            </div>
            
            <input class="btn-2" type="submit" value="Register">
        </form>        
    </body>
</html>

With this html and CSS, we get the result below: inserir a descrição da imagem aqui

And in my javascript I’m creating a table and entering data, like this:

var db = openDatabase("Meubanco", "2.0", "Mybase", 4048);
db.transaction(function(criar){
    criar.executeSql("CREATE TABLE users (ID PRIMARY KEY, nome TEXT, senha TEXT)");
});

function save(){
    var user = document.getElementById('user').value;
    var senha = document.getElementById('senha').value;
    db.transaction(function(armazenar){
        armazenar.executeSql('INSERT INTO users (user,senha) VALUES (?,?)',[user,senha]);
    });
}

However it is not working, I looked at some fonts and can not find error. The table is always empty, so: inserir a descrição da imagem aqui

Can someone help me, pfv?!!

  • 1

    If you want to continue using Sqlite lib, just do a search query, so you will be able to see your data.

1 answer

1


Friend, is that you are not using Websql, although she use Sqlite under the cloths, Websql is an integrated HTML API, so I saw, you added a lib from Sqlite, to use Websql you do not need it, just be with a compatible version of the browser.

If you remove the import of the Sqlite script from HTML, it will probably already work.

You can check compatibility using Javascript.

If(window.openDatabase){
     //implementação
 }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.