Inserting data with PHP using classes and PDO

0

Good evening everyone. I have the task of creating a complete CRUD on the site where I work. However I need to use classes and methods with PHP. See what happens.

I have class usuario.class , where I put all attributes and methods Get and Set , as well as methods of inserting data.

public function insert(){

    try{
        $insert = $this->con->conectar()->prepare("INSERT INTO web_cadcli(nm_cliente, email_cliente, senha_cliente, id_identpess, img) values(:nome, :email, :Senha, :value,  :imagem);");
        $insert->bindParam(":nome",  $this->nome, PDO::PARAM_STR);
        $insert->bindParam(":email", $this->email, PDO::PARAM_STR);
        $insert->bindParam("senha", $this->senha, PDO::PARAM_STR);
        $insert->bindPAram(":value", $this->tpessoa, PDO::PARAM_STR);
        $insert->bindParam(":imagem",$this->imagem, PDO::PARAM_STR);

        if($insert->execute()){
            return 'ok';
        }else{
            return 'erro';
        }  
    }catch(PDOexception $erro_1){
        echo 'erro'.$erro_1->getMessage();
    }
}

It happens that when accessing the template it gives error in the insertion line where the execute is. I step the values through the code below contained in the form.

$usuario = new Usuario();

// Cadastro de Usuario
if ( isset($_POST['cadastrar']) ):

    $nome  = $_POST['nome'];
    $email = $_POST['email'];
    $senha = $_POST['senha'];
    $imagem= $_POST['imagem'];

    $usuario->setNome($nome);
    $usuario->setEmail($email);
    $usuario->setSenha($senha);
    $usuario->setImagem($imagem);

    if($usuario->insert()){

        echo '<div class="alert alert-success alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <strong>OK!</strong> Incluido com sucesso!!! </div>';

    } else {
        echo '<div class="alert alert-danger alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <strong>OK!</strong> Erro ao Cadastrar!!! </div>';
    }
endif;
    
asked by anonymous 02.06.2017 / 03:11

1 answer

0

From the image you posted, your problem is on lines 64 and 67. On line 64 you set the parameter :Senha (with the "S" in upper case). Already on line 67 you use the parameter :senha (with the "s" lowercase).

That is, the parameter :senha with "s" lowercase does not exist. Edit line 64 and change the parameter :Senha to :senha and it will work.

    
02.06.2017 / 03:50