How to rerun an sql statement using ajax?

0

I have a question as to how I can rerun the sql statement again, when sending the form via ajax.

Here is the code of the sentence that is executed

$conexion = $this->conectar();

        $sql = "SELECT * FROM usuarios WHERE usuario = ? AND pass = ?";

        $consulta_preparada = $conexion->prepare($sql);

        $consulta_preparada->execute(array($this->nombre, $this->pass));

        //rowCount devuelve el numero de filas con las que ha coincidido, 1 o 0

        $login = $consulta_preparada->rowCount();

        if ($login > 0) {

            $datos = new stdClass();

            $datos->permiso = "1";
            $datos->usuario = "Shum";
            $datos->edad = "18";

            header('Content-type: application/json; charset=utf-8');

            $this->json= json_encode($datos);

        }else {

            $datos = new stdClass();

            $datos->permiso = "0";

            header('Content-type: application/json; charset=utf-8');

            $this->json = json_encode($datos);

        }

        $this->conexion = null;

once it is executed, it returns all the data normal and fine, but when I insert another name and I send it, nothing happens, that is, it does not execute the query, however if I do it with if-else it does (obvious is test), for example:

if ($nombre == "Shum") {

    retorna algo

}else if () {

    retorna algo 

}else if () {

    retorna algo
}

and if the form is updated, how can I do it but with the query? I hope you understand me xD, thanks:)

    
asked by Shum 03.07.2018 в 04:22
source

0 answers