-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.php
More file actions
78 lines (62 loc) · 2.58 KB
/
process.php
File metadata and controls
78 lines (62 loc) · 2.58 KB
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
<?php
session_start();
$mysqli = new mysqli('localhost', 'root', 'password', 'crud') or die (mysqli_error($mysqli));
// Configurar variables
$ID = 0;
// Limpiar variables
$nombres = '';
$apellidos = '';
$nacimiento = '';
$email = '';
$telefono = '';
// variable para cambiar estado del botón de 'Guardar' a 'Actualizar'
$actualizar = false;
// Guardar datos
if(isset($_POST['guardar'])){
$nombres = $_POST['nombres'];
$apellidos = $_POST['apellidos'];
$nacimiento = $_POST['nacimiento'];
$email = $_POST['email'];
$telefono = $_POST['telefono'];
$mysqli->query("INSERT INTO data (nombres, apellidos, nacimiento, email, telefono) VALUES('$nombres', '$apellidos', '$nacimiento','$email','$telefono')") or die($mysqli->error());
$_SESSION['message'] = "Registro ha sido guardado!";
$_SESSION['msg_type'] = "success";
header("location: index.php");
}
// Eliminar datos
if(isset($_GET['eliminar'])){
$id = $_GET['eliminar'];
$mysqli->query("DELETE FROM data WHERE id=$id") or die($mysqli->error());
$_SESSION['message'] = "Registro ha sido eliminado!";
$_SESSION['msg_type'] = "danger";
header("location: index.php");
}
// Editar datos
if(isset($_GET['editar'])){
$ID = $_GET['editar'];
// variable para cambiar estado del botón de 'Guardar' a 'Actualizar'
$actualizar = true;
$result = $mysqli->query("SELECT * FROM data WHERE ID=$ID") or die($mysqli->error());
if (count($result)==1){
$row = $result->fetch_array();
$nombres = $row['nombres'];
$apellidos = $row['apellidos'];
$nacimiento = $row['nacimiento'];
$email = $row['email'];
$telefono = $row['telefono'];
}
}
// Actualizar Datos
if(isset($_POST['actualizar'])){
$ID = $_POST['ID'];
$nombres = $_POST['nombres'];
$apellidos = $_POST['apellidos'];
$nacimiento = $_POST['nacimiento'];
$email = $_POST['email'];
$telefono = $_POST['telefono'];
$mysqli->query("UPDATE data SET nombres='$nombres', apellidos='$apellidos', nacimiento='$nacimiento', email='$email', telefono='$telefono' WHERE ID=$ID") or die($mysqli->error);
$_SESSION['message'] = "Registro ha sido actualizado! en ID:".$ID;
$_SESSION['msg_type'] = "warning";
header("location: index.php");
}
?>