0
I’m making a system, I followed all the steps to insert the data into the table using sqlite, but when I go to the Application in the part of inspecting the browser element the database remains empty. I would also like to know what to do in the code for an image to be inserted...
JS with sqlite:
var db = openDatabase("Meubanco", "3.0", "Mybase", 6000);
db.transaction(function(criar){
criar.executeSql("CREATE TABLE granjas (codigo PRIMARY KEY, nome TEXT, email TEXT, cnpj TEXT)")
});
function cadastrar(){
var codigo = document.getElementById("codigo").value;
var nome = document.getElementById("nome").value;
var email = document.getElementById("email").value;
var cnpj = document.getElementById("cnpj").value;
db.transaction(function(armazenar){
armazenar.executeSql("INSERT INTO granjas (codigo, nome, email, cnpj) VALUES (?,?,[email protected],?)", [codigo, nome, email, cnpj]);
});
alert("Granja " + document.getElementById("nome").value + " Cadastrada!");
};
HTML
<form onsubmit="cadastrar();">
<div class="form-group">
<label>Código</label>
<input type="text" class="form-control" id="codigo" placeholder="codigo">
</div>
<div class="form-group">
<label>Nome</label>
<input type="text" class="form-control" id="nome" placeholder="nome">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Endereço de email</label>
<input type="email" class="form-control" id="email" aria-describedby="emailHelp" placeholder="email">
</div>
<div class="form-group">
<label>CNPJ</label>
<input type="text" class="form-control" id="cnpj" placeholder="cnpj">
</div>
<form>
<div class="form-group">
<label for="exampleFormControlFile1">Insira uma imagem da granja<small id="emailHelp" class="form-text text-muted">Ação Opcional.</small></label>
<input type="file" class="form-control-file" id="imagem_da_empresa"/>
</div>
</form>
<button type="button" class="btn btn-primary" onclick="cadastrar();">Cadastrar</button>
I think it’s pretty clear what I’m trying to do... Does anyone know where the mistake is?
is missing the data type of the "code" field in your command to create the table
– Ricardo Pontual
True! but inserted here and after reloading the page continues without saving the changes in the bank.
– L. Guilherme P. Melquiades