<em><em><em><em><!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=utf-8" />
<title>Registro</title>
<style>
h1{
text-align:center;
}
table{
background-color:#0FF;
padding:5px;
border:#666 5px solid;
}
</style>
</head>
<body>
<h1> REGISTRO DE EMPLEADOS</h1>
<form action="insertarRegistros.php" method="get" name="form1">
<table width="15%" align="center">
<tr>
<td> Cedula:</td>
<td><label for="cedula"></label>
<input type="text" name="cedula" id="cedula"></td>
</tr>
<tr>
<td> Nombres:</td>
<td><label for="nombres"></label>
<input type="text" name="nombres" id="nombres"></td>
</tr>
<tr>
<td> Apellidos:</td>
<td><label for="apellidos"></label>
<input type="text" name="apellidos" id="apellidos"></td>
</tr>
<form action="datosImagen.php" method="post" enctype="multipart/form-data">
<tr>
<td>Foto:</td>
<td><label for="foto"></label>
<input type="file" name="foto" id="foto" size="20"></td>
</tr>
</form>
<tr>
<td> Email:</td>
<td><label for="email"></label>
<input type="text" name="email" id="email"></td>
</tr>
<tr>
<td> Ciudad:</td>
<td><label for="ciudad"></label>
<input type="text" name="ciudad" id="ciudad"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="imagen" id="enviado" value="Registrar" /></td>
</tr>
</form>
</table>
</body>
</html>
--------------------------------------------------------------------------------------------------------------------------------------------------------
insertarRegistros.php
<?php
$cedula=$_GET["cedula"];
$nombres=$_GET["nombres"];
$apellidos=$_GET["apellidos"];
$email=$_GET["email"];
$ciudad=$_GET["ciudad"];
$foto=$_GET["imagen"];
global $conexion;
$db_host="localhost";
$db_nombre="madecraftt";
$db_usuario="root";
$db_pass="";
$conexion=mysqli_connect($db_host,$db_usuario,$db_pass,$db_nombre);
if(mysqli_connect_errno()){
echo "Fallo al conectar con la base de datos";
exit();
}
mysqli_select_db($conexion,$db_nombre) or die ("No se encuentra la base de datos");
mysqli_set_charset($conexion,"utf8");
$consulta="insert into empleado(id_empleado, nombre_empleado, apellido_empleado,email_empleado, ciudadResidencia_empleado)
values('$cedula','$nombres','$apellidos','$email','$ciudad')";
$resultado=mysqli_query($conexion, $consulta);
if($resultado==false){
echo"Error en la consulta";
}else{
echo"Registro guardado";
}
?>
<form action="menu.php" method="post" name="form1">
<tr>
<td colspan="2" align="center"><input type="submit"name="enviado"id="enviado"value="Menu"/></td>
</tr>
</form>
--------------------------------------------------------------------------------------------------------------------------------------------------------
datosImagen.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
// Recibimos los datos de la imagen
$nombre_imagen=$_FILES['imagen']['name'];
$tipo_imagen=$_FILES['imagen']['type'];
$tamaño_imagen=$_FILES['imagen']['size'];
if($tamaño_imagen<=3000000){
if($tipo_imagen=="image/jpeg" || $tipo_imagen=="image/jpg" || $tipo_imagen=="image/png"){
// ruta de la carpeta del servido
$carpeta_destino=$_SERVER['DOCUMENT_ROOT'] . '/Curso_PHP/';
// Movemos la imagen del directorio temporal al destino escogido
move_uploaded_file($_FILES['imagen']['tmp_name'],$carpeta_destino.$nombre_imagen);
}else{
echo"Solo se pueden subir imagenes jpeg/jpg/png";
}
} else{
echo "El tamaño es demasiado grande";
}
$db_host="localhost";
$db_nombre="madecraftt";
$db_usuario="root";
$db_pass="";
$conexion=mysqli_connect($db_host,$db_usuario,$db_pass,$db_nombre);
if(mysqli_connect_errno()){
echo "Fallo al conectar con la base de datos";
exit();
}
mysqli_select_db($conexion,$db_nombre) or die ("No se encuentra la base de datos");
mysqli_set_charset($conexion,"utf8");
$sql="insert into empleado (foto) values ('$nombre_imagen')";
$resultado=mysqli_query($conexion, $sql);
?>