Advertisement
Guest User

Untitled

a guest
May 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. <?php
  2.  
  3. require_once '../lib/Banco.php';
  4. require_once 'Aluno.php';
  5.  
  6. class Cadastrar extends Aluno
  7. {
  8. protected $aluno;
  9. public $dns = 'mysql:host=localhost;dbname=alunos';
  10. public $user = 'root';
  11. public $pass = 'vertrigo';
  12.  
  13. public function __construct($aluno)
  14. {
  15. $this->aluno = new Aluno($aluno);
  16. $this->insert();
  17. }
  18.  
  19. public function insert()
  20. {
  21. try {
  22. $pdo = new PDO($this->dns, $this->user, $this->pass);
  23. } catch (PDOException $e) {
  24. die('ERROOOOO' . $e->getMessage());
  25. }
  26. $insert = "INSERT INTO aluno(nome, nota1, nota2, nota3, nota4)
  27. VALUES(:nome, :nota1, :nota2, :nota3, :nota4)";
  28. $stmt = $pdo->prepare($insert);
  29. $stmt->bindValue(':nome', $this->aluno->getNome()); // result: true
  30. $stmt->bindValue(':nota1', $this->aluno->getN1()); // result: true
  31. $stmt->bindValue(':nota2', $this->aluno->getN2()); // result: true
  32. $stmt->bindValue(':nota3', $this->aluno->getN3()); // result: true
  33. $stmt->bindValue(':nota4', $this->aluno->getN4()); // result: true
  34.  
  35. if ($stmt->execute()) { // da maneira que esta o código execute() retorna false
  36. header('Location: ../index.php');
  37. } else {
  38. die('Erro ao cadastrar aluno');
  39. //var_dump($this->aluno->getNome());exit;
  40. }
  41. }
  42. }
  43.  
  44. $cadastrar = new Cadastrar($_POST);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement