Exemple #1
0
 /**
  * Realiza o cadastro de um cliente novo
  * @param Cliente $cliente
  */
 public function novo(Cliente $cliente)
 {
     $query = "INSERT INTO clientes (" . "senha, nome, cpf, email, ddd_telefone, " . "telefone, ddd_celular, celular, data_cadastro) " . "VALUES (:senha, :nome, :cpf, :email, " . ":ddd_telefone, :telefone, :ddd_celular, :celular, :data_cadastro" . ")";
     $stmt = $this->conexao->prepare($query);
     $stmt->bindValue(":senha", $cliente->getSenha(), PDO::PARAM_STR);
     $stmt->bindValue(":nome", $cliente->getNome(), PDO::PARAM_STR);
     $stmt->bindValue(":cpf", $cliente->getCpf(), PDO::PARAM_STR);
     $stmt->bindValue(":email", $cliente->getEmail(), PDO::PARAM_STR);
     $stmt->bindValue(":ddd_telefone", $cliente->getDddTelefone(), PDO::PARAM_STR);
     $stmt->bindValue(":telefone", $cliente->getTelefone(), PDO::PARAM_STR);
     $stmt->bindValue(":ddd_celular", $cliente->getDddCelular(), PDO::PARAM_STR);
     $stmt->bindValue(":celular", $cliente->getCelular(), PDO::PARAM_STR);
     $stmt->bindValue(":data_cadastro", $cliente->getDataCadastro(), PDO::PARAM_STR);
     $stmt->execute();
     // pega o último id inserido
     return $this->conexao->LastInsertId();
 }
Exemple #2
0
require_once 'init.php';
include_once 'clientes.class.php';
//validação da  imagem
$dadosOK = true;
//pega os dados  do formulário
$id = isset($_POST['id']) ? $_POST['id'] : null;
$name = isset($_POST['txtNome']) ? $_POST['txtNome'] : null;
$email = isset($_POST['txtEmail']) ? $_POST['txtEmail'] : null;
$dataCadastro = isset($_POST['txtData']) ? $_POST['txtData'] : null;
//validação simples se campos  estão  vazios
if (empty($name) || empty($dataCadastro) || empty($email)) {
    echo "Campos  devem  ser preenchidos!!";
    exit;
}
//instancia objeto  cliente
$cliente = new Cliente($name, $email, $dataCadastro);
//atualiza o BD
$PDO = db_connect();
$sql = "UPDATE clientes SET nomeCliente = :name,  email = :email, dataCadastro = :data WHERE  idCliente = :id";
$stmt = $PDO->prepare($sql);
$stmt->bindParam(':name', $cliente->getNome());
$stmt->bindParam(':email', $cliente->getEmail());
$stmt->bindParam(':data', $cliente->getDataCadastro());
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
if ($stmt->execute()) {
    header('Location: index.php');
} else {
    echo "Erro ao  alterar";
    print_r($stmt->errorInfo());
}