php does not save in database

0

good, I'm doing a php mvc tutorial and I have the problem that I do not run the PDO, I thought it could be xampp problem, so change to wamp, and even delete the instance of mysql that had already installed before, thinking that it could be a problem of access (I contacted the creator of the tutorial, and he tells me that he can perform the action without any problem with the code that happens to him), and as a last measure probe change the browser, since use chrome, but in the same way, I still fail, and do not enter the PDO.

This is my users method.modelo.php     static public function mdlInstoreUser ($ table, $ data) {

    $stmt = Conexion::conectar()->prepare("INSERT INTO $tabla(nombre, usuario, password, perfil) VALUES (:nombre, :usuario, :password, :perfil)");

    $stmt->bindParam(":nombre", $datos["nombre"], PDO::PARAM_STR);
    $stmt->bindParam(":usuario", $datos["usuario"], PDO::PARAM_STR);
    $stmt->bindParam(":password", $datos["password"], PDO::PARAM_STR);
    $stmt->bindParam(":perfil", $datos["perfil"], PDO::PARAM_STR);

    if($stmt->execute()){

        return "ok";    

    }else{

        return "error";

    }

    $stmt->close();

    $stmt = null;

}

this is the fragment of my users.controller.php

public function ctrCrearUsuario(){

    if(isset($_POST["nuevoUsuario"])){

        if(preg_match('/^[a-zA-Z0-9ñÑáéíóúÁÉÍÓÚ ]+$/', $_POST["nuevoNombre"]) &&
           preg_match('/^[a-zA-Z0-9]+$/', $_POST["nuevoUsuario"]) &&
           preg_match('/^[a-zA-Z0-9]+$/', $_POST["nuevoPassword"])){

            $tabla = "usuarios";

            $datos = array("nombre" => $_POST["nuevoNombre"],
                           "usuario" => $_POST["nuevoUsuario"],
                           "password" => $_POST["nuevoPassword"],
                           "perfil" => $_POST["nuevoPerfil"]);

            $respuesta = ModeloUsuarios::mdlIngresarUsuario($tabla, $datos);

            if($respuesta == "ok"){

                echo '<script>

                swal({

                    type: "success",
                    title: "¡El usuario ha sido guardado correctamente!",
                    showConfirmButton: true,
                    confirmButtonText: "Cerrar",
                    closeOnConfirm: false

                })
                </script>';


            }   


        }else{

            echo '<script>

                swal({

                    type: "error",
                    title: "¡El usuario no puede ir vacío o llevar caracteres especiales!",
                    showConfirmButton: true,
                    confirmButtonText: "Cerrar",
                    closeOnConfirm: false

                }).then((result)=>{

                    if(result.value){

                        window.location = "usuarios";

                    }

                })


            </script>';

        }


    }


}

this is my class conexion.php

class Conexion{
static public function conectar(){
    $link = new PDO("mysql:host=localhost:3308;dbname=pos","root","");
    $link->exec("set names utf8");
    return $link;
}

}

To clarify, download the sweetalert2 so it is working correctly, because when you should throw an error, throw it correctly, and when you login in the application, log me in correctly

    
asked by Pablo Ezequiel Ferreyra 24.01.2018 в 13:42
source

0 answers