0
Good evening guys. 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 the class usuario.class
, where I put all attributes and methods Get
and Set
, as well as data insertion methods.
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 gives error in the insertion line where the execute
. 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;
Welcome to the community, Rodrigo. First I invite you to do the [tour] to learn the basics of the site. [en.so] has native support for codes, so avoid posting them in image form. Just you [Edit] the question, paste your code, select it and press the shortcut
Ctrl+K
to format it correctly. In case you want to do manual, just add 4 blank spaces before each line of code.– Woss
In advance, at the end of line 64 there seems to be a
;
that doesn’t make much sense.– Woss
Rodrigo, please edit your question by swapping the images for your code in formatted text as indicated in the comment above. Also at the end of your leg it seems that lacked an image.
– Bruno Peres
I even imagine that, at the end of this question, the best thing would be to create another question to deal exclusively with this topic. However, be careful not to generate a question that tends to opinion-based answers.
– Bruno Peres