-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathej6.php
90 lines (89 loc) · 2.97 KB
/
ej6.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
<?php
$registros = array();
$lasInsertID = 0;
//Realizar la conexion con MySQL
$conn = new mysqli("127.0.0.1", "root", "studentpwd", "nw201501");
if($conn->errno){
die("DB no can: " . $conn->error);
}
if(isset($_POST["btnIns"])){
$registro = array();
$registro["codigo"] = 0;
$registro["descripcion"] = $_POST["txtDsc"];
$registro["lugar"] = $_POST["txtLgr"];
$registro["fecha"] = $_POST["txtFch"];
$registro["contactemail"] = $_POST["txtCrr"];
$registro["status"] = $_POST["txtSts"];
//Preparar el Insert Statement
$sqlstr = "INSERT INTO `charlas` ( `descripcion`, `lugar`, `fecha`, `contactemail`, `status`)";
$sqlstr .= "VALUES ( '". $registro["descripcion"] ." ' , '" . $registro["lugar"] . "', '". $registro["fecha"] ."', '" . $registro["contactemail"] . "', '". $registro["status"] ."');";
//Ejecutar el Insert Statement
$result = $conn->query($sqlstr);
//Obtener el último codigo generado
$lasInsertID = $conn->insert_id;
}
$sqlQuery = "Select * from charlas;";
$resulCursor = $conn->query($sqlQuery);
while($registro = $resulCursor->fetch_assoc()){
$registros[] = $registro;
}
//Obtener los registros de la tabla
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Primer Formulario con MySQL Backend</title>
</head>
<body>
<h1>Charlas</h1>
<form action="ej6.php" method="POST">
<label for="txtDsc">Descripción</label>
<input type="text" name="txtDsc" id="txtDsc" />
<br/>
<label for="txtLgr">Lugar</label>
<input type="text" name="txtLgr" id="txtLgr" />
<br/>
<label for="txtFch">Fecha</label>
<input type="date" name="txtFch" id="txtFch" />
<br/>
<label for="txtCrr">Correo de Contacto</label>
<input type="email" name="txtCrr" id="txtCrr" />
<br/>
<label for="txtSts">Estado</label>
<select name="txtSts" id="txtSts">
<option value="PND">Pendiente</option>
<option value="CNF">Confirmado</option>
<option value="CNL">Cancelado</option>
</select>
<br/>
<input type="submit" name="btnIns" value="Grabar" />
</form>
<div>
<h2>Datos</h2>
<?php if($lasInsertID) echo "Último ID generado = $lasInsertID" ?>
<table>
<tr>
<th>Codigo</th>
<th>Descripción</th>
<th>Lugar</th>
<th>Fecha</th>
<th>Correo</th>
<th>Estado</th>
</tr>
<?php
if(count($registros) > 0){
foreach($registros as $registro){
echo "<tr><td>".$registro["codigo"]."</td>";
echo "<td>".$registro["descripcion"]."</td>";
echo "<td>".$registro["lugar"]."</td>";
echo "<td>".$registro["fecha"]."</td>";
echo "<td>".$registro["contactemail"]."</td>";
echo "<td>".$registro["status"]."</td></tr>";
}
}
?>
</table>
</div>
</body>
</html>