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">×</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">×</span></button>
<strong>OK!</strong> Erro ao Cadastrar!!! </div>';
}
endif;