· 7 years ago · Sep 29, 2018, 02:06 PM
1include_once 'acesso_bd/conexao_bd.php';
2
3class PropriedadeDAO {
4
5
6 function inserirPropriedadeBD($propriedade) {
7
8 $nome = $propriedade->getNome();
9 $endereco = $propriedade->getEndereco();
10 $telefone = $propriedade->getTelefone();
11
12 $conexaobd = new ConexaoBD;
13
14 $conexao = $conexaobd->conectarAoBD();
15
16 $sql = "INSERT INTO propriedade (nome, endereco, telefone) VALUES ('$nome', '$endereco', '$telefone')";
17
18 if (!mysqli_query($conexao, $sql)) {
19 echo "Erro: " . $sql . "<br>" . mysqli_error($conexao);
20 }
21
22
23 }
24
25include_once 'acesso_bd/conexao_bd.php';
26
27class TalhaoDAO {
28
29
30 function inserirTalhaoBD($talhao) {
31
32 $nome = $talhao->getNome();
33
34
35 $conexaobd = new ConexaoBD;
36
37 $conexao = $conexaobd->conectarAoBD();
38
39
40 $sql = "INSERT INTO talhao (nome, id_propriedade) VALUES ('$nome', LAST_INSERT_ID())";
41
42 if (!mysqli_query($conexao, $sql)) {
43 echo "Erro: " . $sql . "<br>" . mysqli_error($conexao);
44 }
45
46
47 }
48
49CREATE TABLE IF NOT EXISTS `propriedade` (
50 `id_propriedade` int(11) NOT NULL AUTO_INCREMENT,
51 `nome` varchar(20) NOT NULL,
52 `endereco` varchar(20) NOT NULL,
53 `telefone` varchar(20) NOT NULL,
54 PRIMARY KEY (`id_propriedade`)
55) ENGINE=InnoDB ;
56
57CREATE TABLE IF NOT EXISTS `talhao` (
58 `id_parcela` int(11) NOT NULL AUTO_INCREMENT,
59 `nome` varchar(20) NOT NULL,
60 `id_propriedade` int(11) NOT NULL,
61 PRIMARY KEY (`id_parcela`),
62 KEY `id_propriedade` (`id_propriedade`),
63 KEY `id_propriedade_fk` (`id_propriedade`)
64) ENGINE=InnoDB ;
65
66include_once 'acesso_bd/conexao_bd.php';
67
68class PropriedadeDAO {
69
70
71 function inserirPropriedadeBD($propriedade) {
72
73 $nome = $propriedade->getNome();
74 $endereco = $propriedade->getEndereco();
75 $telefone = $propriedade->getTelefone();
76
77 $conexaobd = new ConexaoBD;
78
79 $conexao = $conexaobd->conectarAoBD();
80
81 $sql = "INSERT INTO propriedade (nome, endereco, telefone) VALUES ('$nome', '$endereco', '$telefone')";
82
83 if (!mysqli_query($conexao, $sql)) {
84 echo "Erro: " . $sql . "<br>" . mysqli_error($conexao);
85 }else {
86 $propriedade->setID(mysqli_insert_id($conexao)); // Alteração
87 }
88
89
90 }
91
92<?php
93
94include_once '../dao/dao_propriedade.php';
95
96class Propriedade {
97 private $id;
98 private $nome;
99 private $endereco;
100 private $telefone;
101
102 function setID($id) {
103 $this->id = $id;
104 }
105
106 function setNome($nome) {
107 $this->nome = $nome;
108 }
109
110 function setEndereco($endereco) {
111 $this->endereco = $endereco;
112 }
113
114 function setTelefone($telefone) {
115 $this->telefone = $telefone;
116 }
117
118 function getID() {
119 return $this->id;
120 }
121
122 function getNome() {
123 return $this->nome;
124 }
125
126 function getEndereco() {
127 return $this->endereco;
128 }
129
130 function getTelefone() {
131 return $this->telefone;
132 }
133
134include_once 'acesso_bd/conexao_bd.php';
135include_once '../modelo/modelo_propriedade.php';
136
137class TalhaoDAO {
138
139
140
141 function inserirTalhaoBD($talhao) {
142
143 $nome = $talhao->getNome();
144 $idPropriedade = $talhao->getPropriedade(); //Alteração
145
146
147 $conexaobd = new ConexaoBD;
148
149 $conexao = $conexaobd->conectarAoBD();
150
151
152 $sql = "INSERT INTO talhao (`nome`, `id_propriedade`) VALUES ('$nome', '$idPropriedade')";
153
154 if (!mysqli_query($conexao, $sql)) {
155 echo "Erro: " . $sql . "<br>" . mysqli_error($conexao);
156 }
157
158
159 } `
160
161include_once '../dao/dao_talhao.php';
162
163class Talhao {
164 private $id;
165 private $nome;
166 private $endereco;
167 private $telefone;
168 private $id_propriedade;
169
170 function setID($id) {
171 $this->id = $id;
172 }
173
174 function setNome($nome) {
175 $this->nome = $nome;
176 }
177
178 function setPropriedade($id_propriedade){
179 $this->id_propriedade = $id_propriedade;
180 }
181
182
183 function getID() {
184 return $this->id;
185 }
186
187 function getNome() {
188 return $this->nome;
189 }
190
191 function getPropriedade(){
192 return $this->id_propriedade;
193 }`
194
195<body>
196<h1> Nova propriedade</h1>
197<form action="../controle/controle_propriedade.php" method="post">
198 Nome:
199 <br/>
200 <input name="nome" type="text" value="" required="required">
201 <br/>
202 Endereco:
203 <br/>
204 <input name="endereco" type="text" value="" required="required">
205 <br/>
206 Telefone:
207 <br/>
208 <input name="telefone" type="text" value="" required="required">
209 <br/>
210 <input name="acao" type="hidden" value="inserir">
211 <br/>
212 <input type="submit" value="Cadastrar">
213</form>
214<br/>
215
216include_once '../modelo/modelo_propriedade.php';
217
218$acao = ($_POST["acao"]);
219
220switch ($acao) {
221 case "inserir":
222 $propriedade = new Propriedade;
223 $propriedade->setNome($_POST["nome"]);
224 $propriedade->setEndereco($_POST["endereco"]);
225 $propriedade->setTelefone($_POST["telefone"]);
226
227 $propriedade->cadastrarPropriedade();
228
229 include_once '../visao/novo_talhao.html';
230
231 break;
232
233CREATE TABLE IF NOT EXISTS talhao (
234 id_parcela int(11) NOT NULL AUTO_INCREMENT,
235 nome varchar(20) NOT NULL,
236 id_propriedade int(11) NOT NULL,
237 PRIMARY KEY (id_parcela),
238CONSTRAINT id_propriedade_fk FOREIGN KEY (id_propriedade) REFERENCES propriedade(id_propriedade)
239)ENGINE=InnoDB;
240
241-- phpMyAdmin SQL Dump
242-- version 4.5.2
243-- http://www.phpmyadmin.net
244--
245-- Host: localhost
246-- Generation Time: Jun 22, 2017 at 11:47 PM
247-- Server version: 10.1.16-MariaDB
248-- PHP Version: 5.5.38
249
250SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
251SET time_zone = "+00:00";
252
253
254/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
255/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
256/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
257/*!40101 SET NAMES utf8mb4 */;
258
259--
260-- Database: `teste`
261--
262
263-- --------------------------------------------------------
264
265--
266-- Table structure for table `propriedade`
267--
268
269CREATE TABLE `propriedade` (
270 `id_propriedade` int(11) NOT NULL,
271 `nome` varchar(20) NOT NULL,
272 `endereco` varchar(20) NOT NULL,
273 `telefone` varchar(20) NOT NULL
274) ENGINE=InnoDB DEFAULT CHARSET=utf8;
275
276-- --------------------------------------------------------
277
278--
279-- Table structure for table `talhao`
280--
281
282CREATE TABLE `talhao` (
283 `id_parcela` int(11) NOT NULL,
284 `nome` varchar(20) NOT NULL,
285 `id_propriedade` int(11) NOT NULL
286) ENGINE=InnoDB DEFAULT CHARSET=utf8;
287
288--
289-- Indexes for dumped tables
290--
291
292--
293-- Indexes for table `propriedade`
294--
295ALTER TABLE `propriedade`
296 ADD PRIMARY KEY (`id_propriedade`);
297
298--
299-- Indexes for table `talhao`
300--
301ALTER TABLE `talhao`
302 ADD PRIMARY KEY (`id_parcela`),
303 ADD KEY `id_propriedade_fk` (`id_propriedade`);
304
305--
306-- AUTO_INCREMENT for dumped tables
307--
308
309--
310-- AUTO_INCREMENT for table `propriedade`
311--
312ALTER TABLE `propriedade`
313 MODIFY `id_propriedade` int(11) NOT NULL AUTO_INCREMENT;
314--
315-- AUTO_INCREMENT for table `talhao`
316--
317ALTER TABLE `talhao`
318 MODIFY `id_parcela` int(11) NOT NULL AUTO_INCREMENT;
319--
320-- Constraints for dumped tables
321--
322
323--
324-- Constraints for table `talhao`
325--
326ALTER TABLE `talhao`
327 ADD CONSTRAINT `id_propriedade_fk` FOREIGN KEY (`id_propriedade`) REFERENCES `propriedade` (`id_propriedade`);
328
329/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
330/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
331/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;