-
Notifications
You must be signed in to change notification settings - Fork 0
/
editar.php
57 lines (53 loc) · 2.09 KB
/
editar.php
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
<?php
/*funcion para filtrar datos del formulario*/
function filtrar($texto){
$texto = htmlentities(strip_tags(trim($texto)));
$texto = strtolower($texto);
return $texto;
}
include("conexion.php");
$conexion=conecta();
// hacemos la consulta de registros
$id = $_GET["id"];
$query = "SELECT * FROM empleados WHERE IdEmp = ".$id ;
$cursor = mysql_query($query, $conexion);
$action = $_POST["action"];
if ($action == "edit") {
$idusuario = $_POST[id];
$nombres = filtrar($_POST[nom]);
$apellidos = filtrar($_POST[ape]);
$cargo = filtrar($_POST[car]);
$mail = filtrar($_POST[mail]);
$genero = filtrar($_POST[gen]);
$telefono = filtrar($_POST[tel]);
$direccion = filtrar($_POST[dir]);
$sql = "UPDATE empleados SET ";
$sql.= "EmpNombre ='".$nombres."', EmpApellido='".$apellidos."', Empcargo ='".$cargo."', EmpMail ='".$mail."', EmpGenero ='".$genero."', EmpTelefono ='".$telefono."', EmpDir ='".$direccion."' ";
$sql.= "WHERE IdEmp =".$idusuario;
mysql_query($sql, $conexion);
header("location: listado.php");
}
?>
<html>
<head>
<title>Editar Usuario</title>
</head>
<body>
<h1>Editar Usuario</h1>
<form method="post" action="editar.php">
<?php while ($fila = mysql_fetch_assoc($cursor)){?>
Nombre:<input name="nom" type="text" value="<?php echo $fila['EmpNombre']; ?>"/>
Apellido:<input name="ape" type="text" value="<?php echo $fila['EmpApellido']; ?>"/>
Cargo:<input name="car" type="text" value="<?php echo $fila['Empcargo']; ?>"/>
e-Mail:<input name="mail" type="text" value="<?php echo $fila['EmpMail']; ?>"/>
Genero:<input name="gen" type="text" value="<?php echo $fila['EmpGenero']; ?>"/>
Telefono:<input name="tel" type="text" value="<?php echo $fila['EmpTelefono']; ?>"/>
Direccion:<input name="dir" type="text" value="<?php echo $fila['EmpDir']; ?>"/>
<input type="hidden" id="id" name="id" value="<?php echo $fila['IdEmp']; ?>" />
<input type="hidden" name="action" value="edit" />
<?php } ?>
<button type="submit">Guardar</button>
<input type="reset" value = "Limpiar"/>
</form>
</body>
</html>