0
I am creating Mysql server persistence for a web application of mine.
For this I am using the xampp and phpmyadmin. I created a database in phpMyAdmin and in my application, in a javascript I have an Ajax request for a file. php that makes this communication with the server.
What happens is, the Ajaxcall function in my . js is called, but the Php file passed to it with an action is simply ignored. Nothing happens with php. I put Words in . php and nothing appears. I put syntax errors and the browser did not even accuse. It means . php is not being accessed... Only I don’t 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();
}
The folder of my application:
My Persistencia.php:
<?php
function conectaDB(){
$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 Persistencia.php not running.
Note: the balance column has automatic filling with 0.
In the Network tab of F12 the following appears when I open an account:
why the tag phpmyadmin? What has to do with the problem?
– Costamilam
You’re showing it on the console:
console.log("Requisicao http em curso");
?– Sam
Yes, it shows
– Lucas Pletsch
@Guilhermecostamilam tag phpMyAdmin? Where? phpmyadmin is where the mysql server I am using
– Lucas Pletsch
The database server is not in phpmyadmin, it is an interface that you use to access the bd. Use the phpmyadmin tag when the problem is related to it and not why you use it to check whether something worked or not
– Costamilam