-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathenviardatos.php
91 lines (71 loc) · 2.05 KB
/
enviardatos.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Muestra de datos en BBDD</title>
<style type="text/css">
table {
border: solid 2px #7e7c7c;
border-collapse: collapse;
}
th, h1 {
background-color: #edf797;
}
td,
th {
border: solid 1px #7e7c7c;
padding: 2px;
text-align: center;
}
</style>
</head>
<body>
<?php
$user = "root";
$pass = "";
$host = "localhost";
$conexion = mysqli_connect($host, $user, $pass);
if(!$conexion) {
die("No se ha podido conectar con el servidor: " . mysqli_error());
}
$datab = "formulario";
$db = mysqli_select_db($conexion, $datab);
if(!$db) {
die("No se ha podido encontrar la Tabla: " . mysqli_error());
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$edad = $_POST["edad"];
$kilogramos = $_POST["kilogramos"];
$colesterol = $_POST["colesterol"];
$hemoglobina = $_POST["hemoglobina"];
$instruccion_SQL = "INSERT INTO tabla (edad, kilogramos, colesterol, hemoglobina)
VALUES ('$edad', '$kilogramos', '$colesterol', '$hemoglobina')";
$resultado = mysqli_query($conexion, $instruccion_SQL);
if (!$resultado) {
die("Error al insertar datos: " . mysqli_error($conexion));
}
}
$consulta = "SELECT * FROM tabla";
$result = mysqli_query($conexion, $consulta);
if (!$result) {
die("No se ha podido realizar la consulta: " . mysqli_error($conexion));
}
echo "<table>";
echo "<tr>";
echo "<th>edad</th>";
echo "<th>kilogramos</th>";
echo "<th>colesterol</th>";
echo "<th>hemoglobina</th>";
echo "</tr>";
while ($colum = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $colum['edad'] . "</td><td>" . $colum['kilogramos'] . "</td><td>" . $colum['colesterol'] . "</td><td>" . $colum['hemoglobina'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conexion);
echo '<a href="index.html"> Atras</a>';
?>
</body>
</html>