0
I’m not being able to save data in mysql database with ajax, can anyone help? Not error or anything, just not saved. PHP:
$serve = mysql_connect('localhost', 'root', '');
if(!$serve){ echo 'erro';}
$db = mysql_select_db('observatoriogaia', $serve);
if($_GET['acao']=='btnCadCadastra'){
$nome = $_GET['nome'];
$email = $_GET['email'];
$senha = $_GET['senha'];
$SQL = "INSERT INTO usuarios (nome, email, senha)
VALUES ('$nome','$email','$senha')";
$re = mysql_query($SQL, $serve);
}
Javascript:
var $server;
$server = 'http://localhost/';
$(document).on("click", "#btnCadCadastra", function(evt)
{
$nome = $('#idNome').val();
$email = $('#idEmail').val();
$senha = $('#idSenha').val();
$.ajax({
type: "get",
url: $server+"/conecta.php",
data: "nome="+$nome+"&acao=btnCadCadastra",
data: "email="+$email+"&acao=btnCadCadastra",
data: "senha="+$senha+"&acao=btnCadCadastra",
success: function(data) {
intel.xdk.notification.alert('Usuário cadastrado');
}
});
});
HTML:
<div class="upage-content ac0 content-area vertical-col left" id="page_72_85">
<div class="table-thing with-label widget uib_w_8 d-margins" data-uib="jquery_mobile/input" data-ver="0">
<label class="narrow-control label-top-left" for="idNome">Nome de Usuário</label>
<input class="wide-control" placeholder="Ex: Gabriel" type="text" id="idNome" name="nome">
</div>
<div class="table-thing with-label widget uib_w_9 d-margins" data-uib="jquery_mobile/input" data-ver="0">
<label class="narrow-control label-top-left" for="idEmail">Email:</label>
<input class="wide-control" placeholder="seuemail@..." type="email" id="idEmail" name="email">
</div>
<div class="table-thing with-label widget uib_w_10 d-margins" data-uib="jquery_mobile/input" data-ver="0">
<label class="narrow-control label-top-left" for="idSenha">Senha</label>
<input class="wide-control" placeholder="**********" type="password" id="idSenha">
</div>
<div data-role="controlgroup" class="uib-jqm-flex widget uib_w_11 d-margins" data-uib="jquery_mobile/button_group" data-ver="0" data-type="horizontal">
<a class="widget uib_w_12" data-uib="jquery_mobile/button" data-ver="0" data-role="button" data-icon="delete" data-mini="true" id="btnCadCancela">Cancelar</a><a class="widget uib_w_14" data-uib="jquery_mobile/button" data-ver="0"
data-role="button" data-mini="true" data-icon="check" id="btnCadCadastra">Cadastrar</a>
</div>
</div>
Problem solved! My lack of attention did not let me see that I should import the javascript file after importing the plugins from Jquery Mobile, which resulted in error that is, the action was not being executed... Thanks For the help!
– G. Vilela