3
Next, I have the following method in a class called UsuarioDAO
.
public function insertUser(PojoUser $user) {
if ($stmt = Conn::con() != null) {
$stmt = Conn::con()->prepare('INSERT INTO usuario (email, username, password, lastaccess, active, createdat, updatedat) VALUES (:email, :username, :password, :lastaccess, :active, :createdat, :udatedat)');
$stmt->bindValue(":email", $user->getEmail(), PDO::PARAM_STR);
$stmt->bindValue(":username", $user->getUsername(), PDO::PARAM_STR);
$stmt->bindValue(":password", $user->getPassword(), PDO::PARAM_STR);
$stmt->bindValue(":lastaccess", $user->getLastAccess(), PDO::PARAM_STR);
$stmt->bindValue(":active", $user->getActive(), PDO::PARAM_INT);
$stmt->bindValue(":createdat", $user->getCreatedAt(), PDO::PARAM_STR);
$stmt->bindValue(":udatedat", $user->getUpdatedAt(), PDO::PARAM_STR);
$stmt->execute();
} else {
echo "<p class='msg-error'> Desculpe! Erro ao estabelecer conexão. Tente novamente mais tarde.</p>";
}
}
This class takes as parameter an object of PojoUser
, follows the code of the class below:
<?php
class PojoUser {
private $id;
private $email;
private $username;
private $password;
private $lastAccess;
private $active;
private $createdAt;
private $updatedAt;
public function getId() {
return $this->id;
}
public function setId($id) {
$this->id = $id;
}
public function getEmail() {
return $this->email;
}
public function setEmail($email) {
$this->email = $email;
}
public function getUsername() {
return $this->username;
}
public function setUsername($username) {
$this->username = $username;
}
public function getPassword() {
return $this->password;
}
public function setPassword($senha) {
$this->senha = $senha;
}
public function getLastAccess() {
return $this->lastAccess;
}
public function setLastAccess($lastAccess) {
$this->lastAccess = $lastAccess;
}
public function getActive() {
return $this->active;
}
public function setActive($active) {
$this->active = $active;
}
public function getCreatedAt() {
return $this->createdAt;
}
public function setCreatedAt($createdAt) {
$this->createdAt = $createdAt;
}
public function getUpdatedAt() {
return $this->createdAt;
}
public function setUpdatedAt($updatedAt) {
$this->updatedAt = $updatedAt;
}
}
?>
I call these two classes on the user registration page:
<?php
include_once('Register.class.php');
include_once('UserDao.class.php');
include_once('PojoUser.class.php');
if ($_POST) {
$email = $_POST['user-email'];
$password = $_POST['user-password'];
$username = $_POST['user'];
$conUserPassword = $_POST['conf-user-password'];
/*$re = new Register();*/
$user = new PojoUser();
$userDAO = new UserDAO();
$data = date('d/m/Y');
if ($password == $conUserPassword) {
if (!($userDAO->userExists($email))) {
if ($userDAO->userNameAvaiable($username)) {
$cryptoPassword = $userDAO->crypto($password);
$user->setEmail($email);
$user->setUsername($username);
$user->setPassword($cryptoPassword);
$user->setLastAccess($data);
$user->setActive(0);
$user->setCreatedAt($data);
$user->setUpdatedAt($data);
$userDAO->insertUser($user);
//echo "<p class='msg-success'>Usuário Cadastrado com sucesso! Confirme seu email por favor.</p>";
} else {
echo "<p class='msg-error'>Desculpe, este nome de usuário não está mais disponível</p>";
}
} else {
echo "<p class='msg-error'>Hey, parece que você já esteve por aqui, este email já está cadastrado em nosso sistema!</p>";
}
} else {
echo "<p class='msg-error'>Verifique se você digitou as senhas corretamente!</p>";
}
}
?>
My problem is that the user is never registered in the bank. Can anyone help me understand why this?
Any error is displayed?
– stderr
No, no mistake at all.
– user42676