forked from obetancourthunicah/IF412NegociosWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathejercicio3.php
66 lines (53 loc) · 1.44 KB
/
ejercicio3.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
<?php
session_start();
function nuevaInformacion($informa){
$informaciones = array();
if(isset($_SESSION["informaciones"])){
$informaciones = $_SESSION["informaciones"];
}
$hasChanged= false;
foreach($informaciones as $informacion => $contador){
if($informacion == $informa){
$contador ++;
$hasChanged = true;
$informaciones[$informacion] = $contador;
}
}
if(!$hasChanged){
$informaciones[$informa] = 1;
}
$_SESSION["informaciones"] = $informaciones;
}
if(isset($_POST["btnAgregar"])){
nuevaInformacion($_POST["txt1"]);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Tabla de Información</title>
</head>
<body>
<h1>Ejercicio 3 de Examen</h1>
<form action="ejercicio3.php" method="POST" >
<label for="txt1">Nombre </label>
<input type="text" name="txt1"
id="txt1" value="" /><br/><br/>
<input type="submit" name="btnAgregar"
id="btnAgregar" value="Nuevo" />
</form>
<br/><br/><br/>
<h1>Datos persistentes en la sesión </h1>
<table border="1">
<tr><th>Nombre</th></tr>
<?php
if(isset($_SESSION["informaciones"])){
foreach($_SESSION["informaciones"] as $informacion => $Contador){
echo "<tr><td>" . $informacion . "</td>";
}
}
?>
</table>
</body>
</html>