PHP - No da error, pero no inserta el registro en la base de datos

 
Vista:
sin imagen de perfil
Val: 9
Ha aumentado su posición en 14 puestos en PHP (en relación al último mes)
Gráfica de PHP

No da error, pero no inserta el registro en la base de datos

Publicado por javier (5 intervenciones) el 06/05/2018 15:59:40
Buenas estoy teniendo problemas, y no se porque no me funciona.


Estoy haciendo un formulario y no me da error, pero "lo inserta bien" y en la base de datos no hay nada.

Un saludo

<!-FICHERO menu.html->

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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-witdh, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimu-scale=1.0">
		<title>Menu</title>
		<link rel="stylesheet" type="text/css" href="css/ejem.css">
		<script type="text/javascript" src="respuesta_rb.js"></script>
		<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
	</head>
	<body>
		<form action="inicio.php" method="post">
			<h2>MENU</h2>
			<ul id="list">
				<li><a href="#">Registrar alumnos</a></li>
				<li><a href="#">Ver registro de Alumnos</a></li>
				<li><a href="#">Mostrar alumno</a></li>
				<li><a href="#">Consultas</a>
					<ul>
						<li><a href="#">Por centro de procedencia/Grupo</a></li>
						<li><a href="#">Orden alfabetico</a></li>
						<li><a href="#">Ambito familiar</a></li>
						<li><a href="#">Disfuncion familiar</a></li>
						<li><a href="#">Trayectoria escolar</a></li>
						<li><a href="#">Curso</a></li>
						<li><a href="#">Asistencia</a></li>
					</ul>
				</li>
			</ul>
			<fieldset id="f1">
				<div id="datos_b">
				<legend>Datos basicos</legend>
<!-- Os comento esta parte por que, quiero empezar a insertar los datos(solo dni,nombre y apellidos) y no me inserta-->
					<label>Dni</label>
					<input name="dni" type="text"> <br>
 
					<label>Nombre</label>
					<input name="nombre" type="text">
 
					<label>Apellido</label>
					<input name="apellido" type="text"><br>
 
					<label for="fech">Fecha de Nacimiento</label>
					<input name="fech" id="fech" type="date"><br>
					<label>Centro de Procedencia</label> <br>
					<label>
					<input name="cent" type="radio" value="car">
					Carmona Sosa
					</label>
					<label>
					<input name="cent" type="radio" value="par">
					El Parque
					</label>
					<input name="cent" type="radio" value="ferr">
					Ferrobus
					</label>
					<label>
					<input name="cent" type="radio" value="sebas">
					San Sebastian
					</label> <br>
					<br>
 
					<label for="tut">Nombre de Tutor/a</label>
					<input name="tut" id="tut" type="text"><br>
 
					<label>Grupo</label> <br>
					<input name="grupo" type="radio" value="A">
					A
					</label> <br>
					<label>
					<input name="grupo" type="radio" value="B">
					B
					</label> <br>
					<label>
					<input name="grupo" type="radio" value="C">
					C
					</label> <br>
				</div>
			</fieldset>
			<fieldset id="datos_ent">
				<legend>Datos del entorno familiar</legend>
					<label>Ambito familiar</label> <br>
					<h5>Vive con:</h5>
					<label>
					<input name="fam[]" type="checkbox" value="Padre">
					Padre
					</label> <br>
					<label>
					<input name="fam[]" type="checkbox" value="Madre">
					Madre
					</label> <br>
					<label>
					<input name="fam[]" type="checkbox" value="Hermanos">
					Hermanos
					</label> <br>
					<label>
					<input name="fam[]" type="checkbox" value="Abuelos">
					Abuelos
					</label> <br>
					<br>
 
					<label>La relacion con la familia ha sido...</label> <br>
					<input name="tipo_rel" type="radio" value="op1">
					<label>
					De colaboracion: se puede contar con ella
					</label> <br>
					<label>
					<input name="tipo_rel" type="radio" value="op2">
					De colaboracion a demanda del centro
					</label> <br>
					<label>
					<input name="tipo_rel" type="radio" value="op3">
					De demanda constante por parte de la familia
					</label> <br>
					<label>
					<input name="tipo_rel" type="radio" value="op4">
					Conflictiva: dificilmente se podra trabajar con ella
					</label> <br>
					<label>
					<input name="tipo_rel" type="radio" value="op5">
					Descripcion del problema
					</label><br>
					<textarea name="otra" cols="50" rows="5"></textarea>
					<br>
 
					<label>¿Hay algun tipo de disfuncion familiar?</label>
					<input name="cond_1" type="radio" value="d1">
					Si
					</label>
					<label>
					<input name="cond_1" type="radio" value="d2">
					No
					</label> <br>
 
					<label>
					<input name="disf1" type="checkbox" value="padr_tut">
					Padres/tutores con discapacidad
					</label> <br>
					<label>
					<input name="disf2" type="checkbox" value="fam_disc">
					Familiares cercanos con discapacidad
					</label> <br>
					<label>
					<input name="disf3" type="checkbox" value="prob_fam">
					Problemas familiares de drogadiccion
					</label> <br>
					<label>
					<input name="disf4" type="checkbox" value="divorcio">
					Situaciones de divorcio,viudedad,separación
					</label> <br>
					<label>
					<input name="disf5" type="checkbox" value="probl_judic">
					Problemas judiciales(familiares en prisión,denuncias,etc)
					</label> <br>
					<br>
 
					<label>Informacion de interes sobre problemas de salud</label><br>
					<textarea name="salud" cols="50" rows="5" placeholder="Informacion salud del alumno"></textarea>
				</div>
			</fieldset>
			<fieldset id="f3">
				<legend>Trayectoria escolar</legend>
                <table border="1">
                  <tbody>
                    <tr>
                      <td></td>
                      <th id="asig">Lengua</th>
                      <th id="asig">Matematicas</th>
                      <th id="asig">Ingles</th>
                      <th id="asig">Conocimiento</th>
                    </tr>
                    <tr>
                      <th>1º CICLO PRIMARIA</th>
                      <td><input name="leng" type="radio" value="pos_1">1</td>
                      <td><input name="mates" type="radio" value="pos_2">2</td>
                      <td><input name="ingl" type="radio" value="pos_3">3</td>
                      <td><input name="cono" type="radio" value="pos_4">4</td>
                    </tr>
                    <tr>
                      <th>2º CICLO PRIMARIA</th>
                      <td><input name="leng" type="radio" value="pos_5">5</td>
                      <td><input name="mates" type="radio" value="pos_6">6</td>
                      <td><input name="ingl" type="radio" value="pos_7">7</td>
                      <td><input name="cono" type="radio" value="pos_8">8</td>
                    </tr>
                    <tr>
                      <th>3º CICLO PRIMARIA</th>
                      <td><input name="leng" type="radio" value="pos_9">9</td>
                      <td><input name="mates" type="radio" value="pos_10">10</td>
                      <td><input name="ingl" type="radio" value="pos_11">11</td>
                      <td><input name="cono" type="radio" value="pos_12">12</td>
                    </tr>
                  </tbody>
                </table> <br>
 
                <label>¿El alumno ha repetido curso?</label><br>
                <label>
                <input name="2prim" type="checkbox" value="curs">
                2º PRIMARIA
                </label> <br>
                <label>
                <input name="4prim" type="checkbox" value="curs">
                4º PRIMARIA
                </label> <br>
                <label>
                <input name="6prim" type="checkbox" value="curs">
                6º PRIMARIA
                </label> <br> <br>
 
                <label>Situacion del alumno</label><br>
                <label>
                <input name="sit1" type="checkbox" value="sit1">
                Presenta necesidades educativas especiales
                </label> <br>
                <label>
                <input name="sit2" type="checkbox" value="sit2">
                Dificultades de aprendizaje
                </label> <br>
                <label>
                <input name="sit3" type="checkbox" value="sit3">
                Integracion tardia al sistema de educacion español
                </label> <br><br>
 
                <label>¿El alumno ha recibido algún tipo de atención "no ordinaria" y/o adicional a lo largo de su escolaridad?</label>
                <input name="aten_" type="radio" value="a1">
                Si
                </label>
                <label>
                <input name="aten_" type="radio" value="a2">
                No
                </label> <br>
 
                <label>
                <input name="logo" type="checkbox" value="1">
                Logopeda
                </label> <br>
                <label>
                <input name="fisio" type="checkbox" value="2">
                Fisioterapueta
                </label> <br>
                <label>
                <input name="medico" type="checkbox" value="3">
                Medico E.O.E.
                </label> <br>
                <label>
                <input name="orien" type="checkbox" value="4">
                Orientador E.O.E.
                </label> <br>
                <label>
                <input name="espec" type="checkbox" value="5">
                Especialista once
                </label> <br>
                <label>
                <input name="apoyo" type="checkbox" value="6">
                Apoyo al ciclo
                </label> <br>
                <label>
                <input name="pt" type="checkbox" value="7">
                P.T.
                </label> <br>
                <label>
                <input name="otros" type="checkbox" value="8">
                Otros</label><br>
                <textarea name="otra" cols="50" rows="5"></textarea>
 
                <br> <br>
                <table width="100%" border="1">
                    <tr><th rowspan=4>Asistencia a clase</th>
                        <td>Regular</td> <td><input name="asis" type="radio" value="reg"></td>
                    </tr>
                    <tr>
                        <td>Irregular</td> <td><input name="asis" type="radio" value="irreg"></td>
                    </tr>
                    <tr>
                        <td>Iniciado protocolo de Absentismo</td> <td><input name="asis" type="radio" value="absen"></td>
                    </tr>
                    <tr>
                        <td>Protocolo derivado al ETAE</td> <td><input name="asis" type="radio" value="proto"></td>
                    </tr>
 
                </table>
            </fieldset>
            <tr>
                <td>
                    <input type="submit" name="enviar" value="Enviar">
                </td>
            </tr>
		</form>
	</body>
</html>

//FICHERO inicio.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
<?php
 
	$host = "localhost";
	$usuario = "root";
	$password = "";
	$database = "basedatos_alumnos";
 
	$conexion=mysqli_connect($host,$usuario,$password) or die("Problemas con la conexión");
 
	$dni = $_POST['dni'];
	$nombre = $_POST['nombre'];
	$apellidos = $_POST['apellido'];
 
	if(isset($dni) && !empty($dni) && isset($nombre) && !empty($nombre) && isset($apellidos) && !empty($apellidos)) {
		mysqli_select_db($conexion,$database) or die ("No se ha conectado con la base de datos");
 
		mysqli_query($conexion,"INSERT INTO alumno_corto (Dni_alumno, Nombre_alumno, Apellidos_alumno) VALUES ($dni, $nombre, $apellidos)");
 
		if(!empty($my_error)) {
		echo "Ha habido un error al insertar los valores. $my_error";
		} else {
 
		echo "Los datos han sido introducidos satisfactoriamente";
 
		}
 
	} else {
 
	echo "Error, no ha introducido todos los datos";
 
	}
 
?>
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
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

No da error, pero no inserta el registro en la base de datos

Publicado por xve (6935 intervenciones) el 06/05/2018 21:05:54
Hola Javier, la variable $my_error donde la defines?

Creo que las variables tienen que ir entre comillas... algo así:
1
mysqli_query($conexion,"INSERT INTO alumno_corto (Dni_alumno, Nombre_alumno, Apellidos_alumno) VALUES ('$dni', '$nombre', '$apellidos')");

Prueba a hacer esto:
1
echo "INSERT INTO alumno_corto (Dni_alumno, Nombre_alumno, Apellidos_alumno) VALUES ('$dni', '$nombre', '$apellidos')";
y la consulta que te devuelve, la pegas directamente en tu base de datos, haber si te detecta algún error...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 9
Ha aumentado su posición en 14 puestos en PHP (en relación al último mes)
Gráfica de PHP

otra duda/error

Publicado por javier (5 intervenciones) el 07/05/2018 20:09:18
Muchas gracias me has ayudado, en este pequeño error.

Ahora me ha ocurrido otro error/duda, en unas opciones del formulario de tipo radio button, quiero insertar en una tabla de mi base de datos, el dni y un numero del centro es decir, 1 o 2 o 3 o 4, en función se marque uno u otro, pero al recoger ese entero en la comprobacion, no funciona, me gustaria dejar ese valor de los radio button,ya que el formulario es denso.

Un saludo, espero haberme explicado bien.

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
<!--menu.html-->
<label>Centro de Procedencia</label> <br>
<label>
<input name="cent" type="radio" value="car">
Carmona Sosa
</label>
<label>
<input name="cent" type="radio" value="par">
El Parque
</label>
<input name="cent" type="radio" value="ferr">
Ferrobus
</label>
<label>
<input name="cent" type="radio" value="sebas">
San Sebastian
</label> <br>
 
 
//fichero inicio.php
 
$host = "localhost";
$usuario = "root";
$password = "";
$database = "usando_bd";
 
$dni = $_POST['dni'];
$Centro_proc = $_POST['cent'];
 
if ($Centro_proc == 'car') {
    $Centro_proc = 1;
}
if ($Centro_proc == 'par') {
    $Centro_proc = 2;
}
if ($Centro_proc == 'ferr') {
    $Centro_proc = 3;
}
if ($Centro_proc == 'sebas') {
    $Centro_proc = 4;
}
 
 
$conexion=mysqli_connect($host,$usuario,$password) or die("Problemas con la conexión");
 
$db = mysqli_select_db( $conexion, $database ) or die ( "Upps! Pues va a ser que no se ha podido conectar a la base de datos" );
//echo "conexion realizada";
 
$insert = "INSERT INTO `centro_procedencia_alumno` (`Dni_alumno`, `Id_centro`) VALUES ('".$dni."', "$Centro_proc");";
 
$resultado = mysqli_query( $conexion, $insert ) or die ( "Algo ha ido mal en la consulta a la base de datos");
 
$conexion->close();
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar