I'm creating persistence on MySql server for my own web application.
For this I am using xampp and phpmyadmin. I created a database in phpMyAdmin and in my application, in a javascript I have an Ajax request for a .php file that makes this communication with the server.
What happens is that the AjaxCall function in my .js is called, but the Php file passed to it with an action is simply ignored. Nothing happens to php. I put echos in .php and nothing appears. I put syntax errors and the browser did not even accuse. It means that the .php is not being accessed ... But I do not know why.
My Js:
function abreConta(){
var cpf = document.getElementById('cpf').value;
var agencia = document.getElementById('agencia').value;
var conta = document.getElementById('conta').value;
//As variáveis acima são preenchidas corretamente.
parms = "&cpf"+cpf+"&agencia"+agencia+"&conta"+conta;
ajaxCall("Persistencia.php?action=abreConta" +parms, mudaView);
}
function mudaView(listaParams){
window.alert("Sua conta foi aberta com sucesso. Você será redirecionado ao menu inicial");
mudaMenu("formularioDeAbertura", "menu1");
}
function ajaxCall(stringCall, callback){
var httpRequest = new XMLHttpRequest;
httpRequest.onreadystatechange = function(){
if (httpRequest.readyState === 4) {
if (httpRequest.status === 200) {
console.log("Requisicao http em curso");
callback(httpRequest.responseText);
}
}
};
httpRequest.open('GET', stringCall);
httpRequest.send();
}
My application folder:
MyPersistence.php:
<?phpfunctionconectaDB(){$con=mysqli_connect("localhost","root","","onbank");
if(!$con){
echo "<h2>Erro na conexao com a base dados...</h2>";
echo "<h2> Erro " . mysqli_connect_errno() . ".</h2>";
die();
}
$con->set_charset("utf8");
return $con;
}
if(@$_REQUEST['action'] == "abreConta") //recupera lista de nomes das cidades
{
con = ConectaDB();
$cpf = $con->real_escape_string($REQUEST['cpf']);
$agencia = $con->real_escape_string($REQUEST['agencia']);
$conta = $con->real_escape_string($REQUEST['conta']);
mysqli_query($con,"INSERT INTO contas (agencia,conta,dono) VALUES('$agencia','$conta', '$cpf');");]
$con->close();
//abreConta();
}
if(@_REQUEST['action'] == 'buscaContasCliente')
{
$cpf = buscaCpf();
inicializaListaContas($cpf);
}
function buscaCpf(){
$con = ConectaDB();
$nome = $con->real_escape_string($REQUEST['nome']);
$result = mysqli_query($con, "SELECT cpf FROM clientes WHERE nome='$nome';");
return $result;
}
? >
My database in phpMyAdmin: Not being changed, due to Persistence.php not being executed.
Note:thebalancecolumnhasautocompletewith0.
IntheNetworktaboff12thefollowingappearswhenIopenanaccount: