-
-
Save felipyamorim/c313a65cf29ad5c10047476072dc9581 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Aluno | |
| { | |
| protected $nome; | |
| protected $media; | |
| protected $n1, $n2, $n3, $n4; | |
| public function __construct($dados) | |
| { | |
| $this->nome = $dados['nomeAluno']; | |
| $this->n1 = $dados['nota1']; | |
| $this->n2 = $dados['nota2']; | |
| $this->n3 = $dados['nota3']; | |
| $this->n4 = $dados['nota4']; | |
| } | |
| public function getNome() | |
| { | |
| return $this->nome; | |
| } | |
| public function getN1() | |
| { | |
| return $this->n1; | |
| } | |
| public function getN2() | |
| { | |
| return $this->n2; | |
| } | |
| public function getN3() | |
| { | |
| return $this->n3; | |
| } | |
| public function getN4() | |
| { | |
| return $this->n4; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once '../lib/Banco.php'; | |
| require_once 'Aluno.php'; | |
| class Cadastrar extends Aluno | |
| { | |
| protected $aluno; | |
| public $dns = 'mysql:host=localhost;dbname'; | |
| public $user = 'root'; | |
| public $pass = ''; | |
| public function __construct($aluno) | |
| { | |
| $this->aluno = new Aluno($aluno); | |
| $this->insert(); | |
| } | |
| public function insert() | |
| { | |
| try{ | |
| $pdo = new PDO($this->dns, $this->user, $this->pass); | |
| $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); | |
| $insert = "INSERT INTO aluno(nome, nota1, nota2, nota3, nota4) | |
| VALUES(:nome, :nota1, :nota2, :nota3, :nota4)"; | |
| $stmt = $pdo->prepare($insert); | |
| $stmt->bindValue(':nome', $this->aluno->getNome()); | |
| $stmt->bindValue(':nota1', $this->aluno->getN1()); | |
| $stmt->bindValue(':nota2', $this->aluno->getN2()); | |
| $stmt->bindValue(':nota3', $this->aluno->getN3()); | |
| $stmt->bindValue(':nota4', $this->aluno->getN4()); | |
| $stmt->execute(); | |
| header('Location: ../index.php'); | |
| return true; | |
| }catch(Exception $e){ | |
| var_dump($e->getMesage());die; | |
| } | |
| } | |
| } | |
| $cadastrar = new Cadastrar($_POST); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment