You are on page 1of 2

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

<?php /* * * * * * * * * * * * * * * * * * * */

insert.php Copyright 2011 Juan Francisco Ramirez Aceves <FCO@trinity> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Ejemplo de Insert con Lista</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta name="generator" content="Geany 0.19.2" /> </head> <body> <?php if (!$_GET) { $conn = mysql_connect('localhost','admin','es3tu1pi9do0') or die('No se puede conectar con el servidor, Error: '.mysql_error()); $bdpredial = mysql_select_db('empleados',$conn) or die('No se puede seleccionar la Base de Datos. Error: '.mysql_error()); $consulta = mysql_query('select codigo, nombre from departamentos', $conn) or die ('Error en la consulta: '.mysql_error()); ?> Alta de Empleado <BR /> <form action="insert.php" method="GET"> Nombre: <input type="text" name="nombre" size="30"> <br> Apellido: <input type="text" name="apellido" size="30"> <br> Departamento: <Select name="Departamento" size="1"> <?php while( $depto=mysql_fetch_assoc($consulta)) { echo '<option value="'.$depto["codigo"].'">'.$depto["nombre"].'</option>'; } ?> </Select> <BR /> <input type="submit" value="Alta"> </form> <?php mysql_close($conn); } else { $conn = mysql_connect('localhost','admin','es3tu1pi9do0') or die('No se puede conectar con el servidor, Error: '.mysql_error()); $bdpredial = mysql_select_db('empleados',$conn) or die('No se puede seleccionar la Base de Datos. Error: '.mysql_error()); $consulta = mysql_query("Insert into empleados (nombre,apellidos,departamento) values ('{$_GET['nom bre']}','{$_GET['apellido']}',{$_GET['Departamento']})", $conn) or die ('Error en la al dar de alta: '.mysql_error()); if ($consulta) { echo 'Empleado dado de alta <BR />'; //$consulta=mysql_query('Select E.id_empleados, E.nombre, E.apellidos, D.nombre as depto from e
- 1 -

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 </html> 104

pleados as E join departamentos as D on departamento=codigo where E.nombre="'.$_GET["nombre"].'" and E.apellido s="'.$_GET["apellido"].'" order by depto, E.id_empleados') $consulta=mysql_query('Select E.id_empleados, E.nombre, E.apellidos, D.nombre as depto from emp leados as E join departamentos as D on departamento=codigo order by depto, E.id_empleados') or die ('Error en la consulta de select al final: '.mysql_error()); $nfilas = mysql_num_rows ($consulta); echo "<TABLE BORDER='1'> <TR> <TH>No. EMP</TH> <TH>NOMBRE</TH> <TH>DEPARTAMENTO</TH> </TR>"; for ($i=0; $i<$nfilas; $i++) { $fila = mysql_fetch_array($consulta); echo "<TR> <TD align='center'>{$fila['id_empleados']}</TD> <TD colspan>{$fila['nombre']} {$fila['apellidos']}</TD> <TD>{$fila['depto']}</TD> </TR>"; } echo "</TABLE>"; } } ?> </body>

- 2 -

You might also like