PHP - EJERCICIO SIN RESOLVER! AYUDA!

 
Vista:

EJERCICIO SIN RESOLVER! AYUDA!

Publicado por CONCHITA (2 intervenciones) el 31/10/2019 14:02:48
¿ME PODRÍAIS AYUDAR A PARTIR DE ESTE CÓDIGOOOOOO A HACER ESTO?
-->
Cada vez que se envíe el formulario:
 Si el nombre está vacío, se mostrará una advertencia.
 Si el nombre que se introdujo no existe en la agenda, y el número de teléfono no está
vacío, se añadirá a la agenda.
 Si el nombre que se introdujo ya existe en la agenda y se indica un número de
teléfono, se sustituirá el número de teléfono anterior.
 Si el nombre que se introdujo ya existe en la agenda y no se indica número de
teléfono, se eliminará de la agenda la entrada correspondiente a ese nombre.
<--

OS DEJO EL CÓDIGO A CONTINUACIÓN: ---------------------------------------------------->


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
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<!--

-->
<html>
 
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Formulario para probar datos</title>
<!-- Preparamos el entorno gráfico para los datos -->
<style type="text/css">
 
div {
padding: 10px 20px
}
 
h1 {
font-family: sans-serif;
font-style: italic;
text-transform: capitalize;
color: #008000;
}
 
.bajoDch {
float: right;
position: absolute;
margin-right: 0px;
margin-bottom: 0px;
bottom: 0px;
right: 0px;
}
 
.altoDch1 {
color: #00f;
float: right;
position: absolute;
margin-right: 0px;
margin-top: 0px;
top: 0px;
right: 0px;
}
 
.altoDch2 {
color: #f00;
float: right;
position: absolute;
margin-right: 0px;
margin-top: 0px;
top: 0px;
right: 0px;
}
 
</style>
</head>
<!-- Comenzamos poniendo el foco del cursor en la pregunta de nombre -->
 
<body onload='document.forms.formulario.nombre.focus()'>
<?php
if (!empty($_POST['datos'])) {
// Se crea un array con todos los datos antiguos indicándole que están separados por coma
$array = explode("," , $_POST['datos']);
 
 
}else{
// Si no hay datos antiguos, sólo reiniciamos las variables globales
$array=array();
 
}
 
array_push($array,$_POST['nombre']);
if (count($array)>1){
echo "<h1>Nombres</h1>";
echo "<table><tr align='center'><th>Nombre</th></tr>";
// Mostramos una fila de la tabla por cada dato a presentar
foreach($array as $nom){
echo "<tr><td>".$nom."</td></tr>";
}
echo "</table>";
}
 
?>
<!-- Creamos una capa en la parte inferior derecha para que no estorben las preguntas -->
<div class="bajoDch">
<!-- Creamos un formulario para enviar sus datos por POST a la misma página -->
<form name="formulario" action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<table style="border: 0px;">
<tr style="background-color: #8080ff;">Introduzca los datos
<!-- Solicitamos el nombre de la persona -->
<td>
<fieldset>
<legend>Nombre</legend>
<input name="nombre" type="text" />
</fieldset>
</td>
 
</tr>
</table>
<input name="datos" type="hidden" value="<?php if (isset($array)) echo implode("," , $array) ?>" />
<input type="submit" value="Enviar" />
</form>
</div>
</body>
 
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder