I'm using Eel to save data to a database. I have an HTML modal with input fields, and I'm trying to save the data to the database when the user clicks the save button. However, when I fill out the input fields and click the save button, the data is not being saved to the database. I'm not sure what's causing this issue. Can anyone help me troubleshoot this problem?
<form id="formsetor" action="#">
<div class="modal-body">
<div class="form-group">
<label for="empresaInput">Empresa</label>
<input type="text" class="form-control" required id="empresaInput" placeholder="Digite a empresa">
</div>
<div class="form-group">
<label for="setorInput">Setor</label>
<input type="text" class="form-control" required id="setorInput" placeholder="Digite o setor">
</div>
<div class="form-group">
<label for="funcaoInput">Função</label>
<input type="text" class="form-control" required id="funcaoInput" placeholder="Digite a função">
</div>
<div class="form-group">
<label for="liderInput">Líder</label>
<input type="text" class="form-control" required id="liderInput" placeholder="Digite o nome do líder">
</div>
</div>
<div class="modal-footer">
<button class="btn btn-secondary required" type="button" data-dismiss="modal">Cancelar</button>
<button type="submit" class="btn btn-primary" onclick="save_setor_js();" id="save_return">Salvar</button>
</div>
</form>
JS
// Novo Setor
async function save_setor_js(){
if ($("#formsetor").valid()) {
const empresa = $('#empresaInput').val();
const setor = $('#setorInput').val();
const funcao = $('#funcaoInput').val();
const lider = $('#liderInput').val();
const result = await eel.btn_save(empresa, setor, funcao, lider)();
alert(result);
}
};
eel.expose(save_returnsetor);
function save_returnsetor(status) {
if (status == "sucess") {
$('#return_register').text('Novo cadastro concluido com sucesso.');
$('#empresaInput').val('');
$('#setorInput').val('');
$('#funcaoInput').val('');
$('#liderInput').val('');
}
if (status == "failure") {
$('#return_register').text('Erro ao cadastrar, verifique os campos em branco.')
}
if (status == "falhou") {
$('#return_register').text('Erro ao cadastrar, contate o administrador.')
}
};
python code
def save_newsetor(empresa, setor, funcao, lider):
try:
connect = sqlite3.connect("web/database/storage.db")
cursor = connect.cursor()
print("Conexão com o banco de dados estabelecida com sucesso!")
if empresa != "" and setor != "" and funcao != "" and lider != "":
cursor.execute("INSERT INTO setor(empresa, setor, funcao, lider) VALUES(?,?,?,?)", (empresa,setor,funcao,lider))
connect.commit()
connect.close()
msg = "sucess"
return msg
else:
msg = "failure"
return msg
except Exception as Error:
print(Error)
msg = "falhou"
return msg
@eel.expose
def btn_save(empresa, setor, funcao, lider):
print("Chamando a função btn_save")
msg = save_newsetor(empresa, setor, funcao, lider)
eel.save_returnsetor(str(msg))
"I've been trying to troubleshoot an issue in my code, but I'm having trouble identifying where the problem is occurring. I've tried adding print statements at various points in the code to see where the execution stops or if there are any errors, but the code isn't returning any prints.
I'm feeling a bit lost as to where to go from here. Does anyone have any suggestions for other debugging techniques I could try or how I can get the code to return prints so I can better understand what's happening?"