PHP - Mensaje de eror - Cannot add or update a child row: a foreign key constraint fails

 
Vista:
sin imagen de perfil

Mensaje de eror - Cannot add or update a child row: a foreign key constraint fails

Publicado por Mario Ramirez (32 intervenciones) el 24/01/2014 02:11:49
Cordial saludo,
buenas noches y tengo un inconveniente, estab funcionando mi db y al montar un menu en css me sale el siguiente mensaje, si me lo pueden explicar les agradezco.
"Problemas en el selectCannot add or update a child row: a foreign key constraint fails (`mario`.`persona`, CONSTRAINT `persona_ibfk_1` FOREIGN KEY (`usuario`) REFERENCES `admin` (`usuario`) ON DELETE CASCADE ON UPDATE NO ACTION)
Muchas gracias
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

Mensaje de eror - Cannot add or update a child row: a foreign key constraint fails

Publicado por xve (6935 intervenciones) el 24/01/2014 08:05:51
Hola Mario no nos muestras la query, pero lo que te esta diciendo, es que estas trabajando con una clave foranea, la cual no puedes añadir o modificar.
Que estas haciendo añadiendo o modificando?
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

Mensaje de eror - Cannot add or update a child row: a foreign key constraint fails

Publicado por Mario Osvaldo (32 intervenciones) el 27/01/2014 01:35:35
Cordial saludo,
Gracias por la colaboracion.
Mira tengo el siguiente problema
Monte una aplicacion donde me logueo y paso a ingresar los datos, con el usuario que me logue es una variable en la db, ese usuario lo paso desde el loguin hasta el procedimeinto formulario (anexo los procedimientos).

luego modifico y mejoro la aplicacion,
monto un menu que realice atraves de los vides de youtobe y hay empieza el problema

me logueo, paso al menu y alli escojo la opcion ingresar (esta es la misma que formulario solo que cambia la presentacion) alli grabo los datos y sale el error, pienso que es que no me esta pasando el usuario desde el loguin hasta el menu y luego al formulario ingresar. anexo el procedimiento.

Agradezco que me colaboren, la idea es que al grabar me grabe el usuario con que me logue
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
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

Mensaje de eror - Cannot add or update a child row: a foreign key constraint fails

Publicado por xve (6935 intervenciones) el 27/01/2014 07:10:33
Hola Mario, gracias por comentarlo.

Para saber si recoge el valor correctamente, te recomiendo que muestres la consulta por pantalla y la pruebes directamente en el MySQL.

Estaría bien si nos puedes mostrar la estructura de las tablas y la consulta insert para poder ayudarte.
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

Mensaje de eror - Cannot add or update a child row: a foreign key constraint fails

Publicado por Mario Osvaldo (32 intervenciones) el 04/02/2014 02:43:03
Cordial saludo,
envio la db, la grafica de la relacio, y el codigo del procedimeinto que saca el error
agradezco la colaboracion que me puedan brindar
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

Mensaje de eror - Cannot add or update a child row: a foreign key constraint fails

Publicado por Mario Osvaldo (32 intervenciones) el 04/02/2014 03:16:47
añadiendo

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
<html>
<head>
<title>MARIO</title>
</head>
<body>
	<?php
		// Inicio la sesión
		session_start();
		header("Cache-control: private"); // Arregla IE 6
		//$_SESSION['usser']  = $_POST['login'];
		//$x= $_session['usser'];
 
		if (($_REQUEST["documento"] == "" ) or ( $_REQUEST["nombres"] == ""))
			{
				echo "<p>Hay campos vacios!No se puede guardar el registro!</p>";
			}
		else
			{
			include("services/config.php");
 
			mysql_query("insert into persona(usuario,fecha,radicado,documento,tipo,nombres,genero,telefono,direccion,barrio,comuna,asunto,contraventor,genero_c,citacion,actuacion,observacion) values
			('$_REQUEST[editarautornuevo]','$_REQUEST[fecha]','$_REQUEST[radicado]','$_REQUEST[documento]','$_REQUEST[tipo]','$_REQUEST[nombres]','$_REQUEST[genero]','$_REQUEST[telefono]','$_REQUEST[direccion]','$_REQUEST[barrio]','$_REQUEST[comuna]','$_REQUEST[asunto]','$_REQUEST[contraventor]','$_REQUEST[genero_c]','$_REQUEST[citacion]','$_REQUEST[actuacion]','$_REQUEST[observacion]')",
 
		$conexion) or die("Problemas en el select".mysql_error());
		$_SESSION['estado'] = "logeado";  // Coloco la variable de sesión 'estado'
 
		echo "<p>creado de forma correcta! <meta http-equiv='Refresh' content='5;url=formulario.php'></p>";
		//echo "<p>creado de forma correcta!</p>"; 
		}
	?>
	<SCRIPT LANGUAGE="javascript">
		alert('Anexar registro?');
		window.history.go(-1)
	</SCRIPT>
 
</form>
</body>
</html>


este es el formulario
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
<?php
// Inicio la sesión
session_start();
header("Cache-control: private"); // Arregla IE 6
    $_SESSION['usser']  = $_POST['login'];
	$login = $_POST['login'];
	$password = $_POST['password'];
 
 
include("services/config.php");
$registros=mysql_query("select *
                      from admin where usuario='".$login."' AND contraseña='".$password."' ",$conexion) or
die("Problemas en el select:".mysql_error());
if ($reg=mysql_fetch_array($registros))
{
 $_SESSION['estado'] = "logeado";  // Coloco la variable de sesión 'estado'
?>
<?php
      echo  $reg['usuario'];
	  ?>
	   <br>
 
 <form  method="post" action="ppal2.php">
	<p>Fecha:
     <input type="text" name="fecha">
   </p>
   <p>Radicado:
     <input type="text" name="radicado">
   </p>
    <p>Documento:
     <input type="text" name="documento">
   </p>
   <p>Tipo:
     <input type="text" name="tipo">
   </p>
   <p>Nombres:
     <input type="text" name="nombres">
   </p>
   <p><br>
     Genero:
     <input type="text" name="genero">
   </p>
   <p><br>
     Telefono:
     <input type="text" name="telefono">
   </p>
	 <p>Direccion:
     <input type="text" name="direccion">
   </p>
	 <p>Barrio:
     <input type="text" name="barrio">
   </p>
	 <p>Comuna:
     <input type="text" name="comuna">
   </p>
	 <p>Asunto:
     <input type="text" name="asunto">
   </p>
   <p>Contraventor:
     <input type="text" name="contraventor">
   </p>
   <p>Genero_c:
     <input type="text" name="genero_c">
   </p>
   <p>Citacion:
     <input type="text" name="citacion">
   </p>
   <p>Actuacion:
     <input type="text" name="actuacion">
   </p>
     <p>Observacion:
     <input type="text" name="observacion">
    </p>
   <p><br>
     <input type="hidden" name="editarautornuevo" value="<?php echo $reg['usuario']  ?>">
 
          <input type="submit" value="Ingresar">
          <label>
          <input type="reset" name="Submit" value="Siguiente" />
          </label>
     <br>
 
     <a href="consultatodos.php" target="_self">CONSULTAR TODOS</a><br>
	 <a href="listar.php" target="_self">LISTAR TODOS</a><br>
	 <a href="pantalla_buscar_documento.php" target="_self">Buscar documento</a><br>
	  <a href="pantalla_buscar_radicado.php" target="_self">Buscar radicado</a><br>
	   <a href="pantalla_buscar_nombres.php" target="_self">Buscar nombres</a><br>
	    <a href="pantalla_buscar_fecha.php" target="_self">Buscar fecha</a><br>
		<a href="explorando_nombres.php" target="_self">Explorando nombres</a><br>
		  <a href="consulta_dependencia.php" target="_self">Listados x dependencia</a><br>
			<a href="exportar_dependencia.php" target="_self">Exportar dependencia</a><br>
			<a href="exportar_todos.php" target="_self">Exportar todos</a><br>
 
 
     <a href="salir.php" target="_self">SALIR</a>     </p>
 </form>
<?php
}
else
  echo "<p>Datos errados!Volver a intentarlo! <meta http-equiv='Refresh' content='5;url=acceso.html'></p>";
?>

este el menu donde selecciono la opcion ingreso
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>
 
 
 
<?php
// Inicio la sesión
session_start();
header("Cache-control: private"); // Arregla IE 6
    $_SESSION['usser']  = $_POST['login'];
   $login = $_POST['login'];
   $password = $_POST['password'];
 
//include("services/config.php"); 
//$registros=mysql_query("select *
  //                    from admin where usuario='".$login."' AND contraseña='".$password."' ",$conexion) or
//die("Problemas en el select:".mysql_error());
//if ($reg=mysql_fetch_array($registros))
//{//
 $_SESSION['estado'] = "logeado";  // Coloco la variable de sesión 'estado'
?>
 
<body>
<p align="center">
  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="103" height="24">
    <param name="movie" value="button3.swf" />
    <param name="quality" value="high" />
    <embed src="button3.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="103" height="24" ></embed>
  </object>
  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="103" height="24">
    <param name="movie" value="button4.swf" />
    <param name="quality" value="high" />
    <embed src="button4.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="103" height="24" ></embed>
  </object>
</p>
<hr />
<p>&nbsp;</p>
</body>
</html>


si tienes un correo para envirtelo, te agradeceria, pienso que se podria enviar mejor la informacion
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