PHP - PHP con POO

 
Vista:

PHP con POO

Publicado por Elena (2 intervenciones) el 24/10/2012 21:36:04
Hola alguien me puede ayudar, estoy haciendo un prog en php OO que crea una clase docente, y luego tengo que guardar esos datos en una base de datos mysql, me da todo bien pero no carga nada en la base de datos. Son clases una docente, una conectar, un formulario y una vista.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
<html>
<head>
<title>Docente</title>
</head>
<body>
<?php
 
class conectar {
public static function con(){
$conexion = mysql_connect("localhost","root","root");
mysql_query("SET NAMES 'utf8'");
mysql_select_db("bdsew");
return 	$conexion;}}
 
// Clase Docente
class Docente {
  public $dni;
  public $ape;
  public $nom;
  public $tel;
  public $carhoraria;
  public $dom;
  public $ema;
  public $fnac;
  public $ain;
 
    // setters getters
  public function getNombre() {
	return $this->Nombre; }
  public function setNombre($nom){
	$this->Nombre = $nom; }
 
  public function getApellido() {
	return $this->Apellido; }
  public function setApellido($ape){
	$this->Apellido = $ape;  }
 
  public function getAñoIngreso() {
	return $this->AñoIngreso; }
  public function setAñoIngreso($ain){
	$this->AñoIngreso = $ain;  }
 
 public function getDni() {
	return $this->Dni; }
  public function setDni($dni){
	$this->Dni = $dni;}
 
 public function getDomicilio() {
	return $this->Domicilioo; }
  public function setDomicilio($dom){
	$this->Domicilio = $dom;  }
 
 public function getemail() {
	return $this->email; }
  public function setemail($ema){
	$this->email = $ema;  	}
 
public function getFechaNac() {
	return $this->FechaNac; }
  public function setFechaNac($fnac){
	$this->FechaNac = $fnac;  }
 
	public function getTelefono() {
	return $this->Telefono; }
  public function setTelefono($tel){
	$this->Telefono = $tel;  }
 
public function getcargaHoraria() {
	return $this->cargaHoraria; }
  public function setcargaHoraria($carhoraria){
	$this->cargaHoraria = $carhoraria;  }
 
 // Metodo Constructor 
  public function insertar($Dni,$Apellido,$Nombre,$Telefono,$cargaHoraria,$Domicilio,$email,$FechaNac,$AñoIngreso){
  $this->Dni=$Dni;
  $this->Apellido=$Apellido;
  $this->Nombre=$Nombre;
  $this->Telefono=$Telefono;
  $this->cargaHoraria=$cargaHoraria;
  $this->Domicilio=$Domicilio;
  $this->email=$email;
  $this->FechaNac=$FechaNac;
  $this->AñoIngreso=$AñoIngreso;
 
$sql = "INSERT INTO docente VALUES
('$this->Dni','$this->Apellido','$this->Nombre','$this->Telefono','$this->AñoIngreso','$this->cargaHoraria','$this->Domicilio','$this->email','$this->FechaNac',$this->AñoIngreso)";
$res = mysql_query ($sql,conectar::con());
echo "datos ingresados";
}
}
 
?>
</body>
</html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<style type="text/css">
<!--
body {
	background-image: url(sew2.jpg);
	background-repeat: no-repeat;
}
.Estilo1 {color: #0000FF}
.Estilo2 {font-size: large}
-->
</style>
 
<table width="955" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutDefaultTable-->
  <tr>
    <td width="494" height="120">&nbsp;</td>
    <td width="162">&nbsp;</td>
    <td width="129">&nbsp;</td>
    <td width="170">&nbsp;</td>
  </tr>
  <tr>
    <td height="141">&nbsp;</td>
    <td colspan="3" valign="top"><h1 class="Estilo1"><img src="logoSEW.png" alt="sew3" width="84" height="98" /><span class="Estilo1">Agregar Otro Docente</span></h1></td>
  </tr>
  <tr>
    <td height="26"></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="97"></td>
    <td>&nbsp;</td>
    <td valign="top"><form id="form1" name="form1" method="post" action="ClaseDocente.php">
      <span class="Estilo2">
      <label>
 
        <input name="Submit" type="submit" class="Estilo2" value="Agregar" />
        </label>
      </span>
<p class="Estilo1">&nbsp;</p>
    </form></td>
  <td>&nbsp;</td>
  </tr>
</table>
<?php
 
include ("ClaseDocente.php");
 
 
	$Dni=$_POST['dni'];
	$Apellido=$_POST['ape'];
	$Nombre=$_POST['nom'];
	$Telefono=$_POST['tel'];
	$cargaHoraria=$_POST['carhoraria'];
	$Domicilio=$_POST['dom'];
	$email=$_POST['ema'];
	$FechaNac=$_POST['fnac'];
	$AñoIngreso=$_POST['ain'];
 
 
$obj=new Docente();
$obj->insertar($Dni,$Apellido,$Nombre,$Telefono,$cargaHoraria,$Domicilio,$email,$FechaNac,$AñoIngreso);
 
?>
 
 
 
 
 
 
 
 
 
 
 
 
<?php
$host = "localhost";
$user = "root";
$pw = "root";
$bd = "bdsew";
 
?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Vista Docente</title>
<h1><center>Listado de Docentes</h1></center>
</head>
 
<center><table border="1" cellspacing=2 cellpadding=8 style="font-size: 8pt"><tr>
<td><font face="verdana"><b>DNI</b></font></td>
<td><font face="verdana"><b>APELLIDO</b></font></td>
<td><font face="verdana"><b>NOMBRE</b></font></td>
<td><font face="verdana"><b>TELEFONO</b></font></td>
<td><font face="verdana"><b>CARGA HORARIA</b></font></td>
<td><font face="verdana"><b>DOMICILIO</b></font></td>
<td><font face="verdana"><b>EMAIL</b></font></td>
<td><font face="verdana"><b>FECHA NACIMIENTO</b></font></td>
<td><font face="verdana"><b>AÑO DE INGRESO</b></font></td>
</tr>
 
 
<?php
include ("conexion.php");
  $conexion = mysql_connect($host,$user,$pw)
      or die ("Error al conectar a la base de datos.");
 mysql_select_db($bd,$conexion)
      or die ("Error al conectar a la base de datos.");
 
  $query = "SELECT dni, ape, nom, tel, carhoraria, dom, ema, fnac, ain "."FROM docente" ;
 
  $result = mysql_query($query);
  $numero = 0;
  while($row = mysql_fetch_array($result))
  {
    echo "<tr><td width=\"10%\"><font face=\"verdana\">" .
	    $row["dni"] . "</font></td>";
    echo "<td width=\"10%\"><font face=\"verdana\">" .
	    $row["ape"] . "</font></td>";
    echo "<td width=\"10%\"><font face=\"verdana\">" .
	    $row["nom"] . "</font></td>";
    echo "<td width=\"10%\"><font face=\"verdana\">" .
	    $row["tel"]. "</font></td>";
	echo "<td width=\"10%\"><font face=\"verdana\">" .
	    $row["carhoraria"] . "</font></td>";
    echo "<td width=\"10%\"><font face=\"verdana\">" .
	    $row["dom"] . "</font></td>";
    echo "<td width=\"10%\"><font face=\"verdana\">" .
	    $row["ema"] . "</font></td>";
    echo "<td width=\"10%\"><font face=\"verdana\">" .
	    $row["fnac"]. "</font></td>";
	echo "<td width=\"10%\"><font face=\"verdana\">" .
	    $row["ain"]. "</font></td></tr>";
    $numero++;
  }
  echo "<tr><td colspan=\"13\"><font face=\"verdana\"><b>Número: " . $numero .
      "</b></font></td></tr>";
 
  mysql_free_result($result);
  mysql_close($conexion);
?>
</table></center>
</html>
 
 
 
 
 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language='javascript' src="popcalendar.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<style type="text/css">
<!--
body {
	background-image: url(sew2.jpg);
	background-repeat: no-repeat;
}
.Estilo1 {
	font-size: xx-large;
	font-weight: bold;
	color: #FF0000;
}
-->
</style></head>
 
<body>
<table width="1159" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutDefaultTable-->
  <tr>
    <td width="430" height="80">&nbsp;</td>
    <td width="20">&nbsp;</td>
    <td width="681">&nbsp;</td>
    <td width="28"></td>
  </tr>
  <tr>
    <td height="65">&nbsp;</td>
    <td>&nbsp;</td>
    <td valign="top"><h1 align="center" class="Estilo1">Agregar Docente </h1></td>
    <td></td>
  </tr>
  <tr>
    <td height="27">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td></td>
  </tr>
  <tr>
    <td height="640">&nbsp;</td>
    <td colspan="3" valign="top"><form id="form1" name="form1" method="post" action="agregarDocente.php">
        <p align="right">
        <label >
          <div align="right">
        </label>
		 <p align="right">
          <label>DNI
          <input name="dni" type="text" size="70" />
          </label>
        </p>
        <p align="right">
          <label>Apellido
          <input name="ape" type="text" size="70" />
          </label>
        </p>
        <p align="right">
          <label>Nombre
          <input name="nom" type="text" size="70" />
          </label>
        </p>
		<p align="right">
          <label>Telefono
          <input name="tel" type="text" size="70" />
          </label>
        </p>
		 <p align="right">
          <label>Carga Horaria
          <input name="carhoraria" type="text" size="70" />
          </label>
        </p>
        <p align="right">
          <label>Domicilio
          <input name="dom" type="text" size="70" />
          </label>
        </p>
		 <p align="right">
          <label>Email
          <input name="ema" type="text" size="70" />
          </label>
        </p>
 
        <p align="right">
          <label>Fecha de Nacimiento(AAAA-MM-DD)
          <input name="fnac" type="text" size="70"   />
		  </label>
        </p>
 
		<p align="right">
          <label>Fecha de Ingreso(AAAA-MM-DD)
          <input name="ain" type="text" size="70"   />
		  </label>
        </p>
 
		 <p align="right">
          <input type="submit" name="Submit" value="Grabar Datos" />
        </p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
    </form></td>
  </tr>
</table>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder