Pregunta:
Fecha: 08-04-2020 21:28:36
(En Español)
de la base de datos cuando registro un cliente
error : Cannot add or update a child row: a foreign key constraint fails (`facturacion2`.`cliente`, CONSTRAINT `cliente_ibfk_1` FOREIGN KEY (`usuario_id`) REFERENCES `usuario` (`idusuario`))
sql no se bien subirlo
cual es el error??? Votos: 0 - Respuestas: 5 - Vistas: 5 Compartir en: Google Facebook Twitter LinkedIn Link
error: no puedo registra un formulario con una tabla relacionada php erro de llave foranea[No resuelta]
tengo un errorde la base de datos cuando registro un cliente
error : Cannot add or update a child row: a foreign key constraint fails (`facturacion2`.`cliente`, CONSTRAINT `cliente_ibfk_1` FOREIGN KEY (`usuario_id`) REFERENCES `usuario` (`idusuario`))
<?php
$host = 'localhost';
$user = 'root';
$password = '';
$db = 'facturacion2';
$conection = @mysqli_connect($host,$user,$password,$db);
if(!$conection){
echo "Error en la conexion";
}
?>
<?php
session_start();
include "../conexion.php";
if(!empty($_POST))
{
$alert='';
if(empty($_POST['nombre']) || empty($_POST['telefono']) || empty($_POST['direccion']))
{
$alert='<p class="msg_error">Todos los campos son obligatorios.</p>';
}else{
$nit = $_POST['nit'];
$nombre = $_POST['nombre'];
$telefono = $_POST['telefono'];
$direccion = $_POST['direccion'];
$usuario_id = $_SESSION['idUser'];
$result = 0;
if(is_numeric($nit) and $nit !=0)
{
$query = mysqli_query($conection,"SELECT * FROM cliente
WHERE nit = '$nit' ");
$result = mysqli_fetch_array($query);
}
if($result > 0){
$alert='<p class="msg_error">El correo o el usuario ya existe.</p>';
}else{
$query_insert = mysqli_query($conection,"INSERT INTO
cliente (nit,nombre,telefono,direccion,usuario_id)
VALUES('$nit','$
nombre','$
telefono','$
direccion','$
usuario_id')");
if(!$query_insert){
printf("error : %s\n", mysqli_error($conection));
}
print_r($query_insert);
if($query_insert){
$alert='<p class="msg_save">Cliente creado correctamente.</p>';
}else{
$alert='<p class="msg_error">Error al crear el cliente.</p>';
}
}
}
mysqli_close($conection);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<?php include "includes/scripts.php"; ?>
<title>Registro Cliente</title>
</head>
<body>
<?php include "includes/header.php"; ?>
<section id="container">
<div class="form_register">
<h1><i class="fas fa-user-plus "></i> Registro Cliente</h1>
<hr>
<div class="alert"><?php echo isset($alert) ? $alert : ''; ?></div>
<form action="" method="post" class="forma">
<label for="nit">Nit</label>
<input type="number" name="nit" id="nit" placeholder="Nit">
<label for="nombre">Nombre</label>
<input type="text" name="nombre" id="nombre" placeholder="Nombre completo">
<label for="telefono">telefono</label>
<input type="number" name="telefono" id="telefono" placeholder="telefono">
<label for="direccion">Dirección</label>
<input type="text" name="direccion" id="direccion" placeholder="Dirección">
<button type="submit" value="Guardar Cliente" class="btn-save"><i class="fas fa-save"></i> Crear cliente</button>
</form>
</div>
</section>
<?php include "includes/footer.php"; ?>
</body>
</html>
<?php
$alert = '';
session_start();
if(!empty($_SESSION['active']))
{
header('location: sistema/');
}else{
if(!empty($_POST)){
if(empty($_POST['usuario']) || empty($_POST['clave'])){
$alert = "ingrese los datos en los botones";
}else{
require_once "conexion.php";
$user = mysqli_real_escape_string($conection,$_POST['usuario']);
$pass = md5(mysqli_real_escape_string($conection,$_POST['clave']));
echo $pass;
$query = mysqli_query($conection,"SELECT * FROM usuario WHERE usuario = '$user'
AND clave = '$pass'");
mysqli_close($conection);
$result = mysqli_num_rows($query);
if($result >0){
$data = mysqli_fetch_array($query);
$_SESSION['active'] = true;
$_SESSION['idUser'] = $data['idUsuario'];//aqui esta la variable de session que necesito para el archivo registro_cliente.php
$_SESSION['nombre'] = $data['nombre'];
$_SESSION['email'] = $data['email'];
$_SESSION['user'] = $data['usuario'];
$_SESSION['rol'] = $data['rol'];
header("location: sistema/");//una vez que se guarden las variables se va a ka carpeta sistema
}else{
$alert = "los datos son incorrectos";
session_destroy();
}
}
}
}//llave de la session con la variable ssession['active']
?>
<!DOCTYPE html>
<html>
<head>
<title>Login | Sistema de Facturación</title>
<link rel="stylesheet" type="text/css" href="css/styles.css">
</head>
<body>
<section id="container">
<form action="" method="post">
<h3>Iniciar Sesión</h3>
<img src="img/1.jpg" alt="Login">
<input type="text" name="usuario" placeholder="usuario">
<input type="password" name="clave" placeholder="contraseña">
<div class="alert"><?php echo isset($alert)? $alert : ''; ?></div>
<input type="submit" value="INGRESAR" >
</form>
</section>
</body>
</html>
sql no se bien subirlo
-- phpMyAdmin SQL Dump -- version 4.7.4 -- https://www.phpmyadmin.net/ -- -- Servidor: 127.0.0.1 -- Tiempo de generación: 03-12-2018 a las 06:54:16 -- Versión del servidor: 10.1.28-MariaDB -- Versión de PHP: 7.1.10 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET AUTOCOMMIT = 0; START TRANSACTION; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Base de datos: `facturacion` -- -- -------------------------------------------------------- -- -- Estructura de tabla para la tabla `cliente` -- CREATE TABLE `cliente` ( `idcliente` int(11) NOT NULL, `nit` int(11) DEFAULT NULL, `nombre` varchar(80) DEFAULT NULL, `telefono` int(11) DEFAULT NULL, `direccion` text, `dateadd` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `usuario_id` int(11) NOT NULL, `estatus` int(11) NOT NULL DEFAULT '1' ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Volcado de datos para la tabla `cliente` -- INSERT INTO `cliente` (`idcliente`, `nit`, `nombre`, `telefono`, `direccion`, `dateadd`, `usuario_id`, `estatus`) VALUES (1, 1234567, 'Willian Juarez', 878766787, 'Guatemala, Guatemala', '2018-02-15 21:55:51', 1, 1), (2, 87654321, 'Marta Gonzales', 34343434, 'Calzada Buena Vista', '2018-02-15 21:57:03', 1, 1), (3, 0, 'Elena Hernández', 987897987, 'Guatemala, Chimaltenango', '2018-02-15 21:59:20', 2, 0), (4, 0, 'Julio Maldonado', 908098979, 'Avenida las Americas Zona 14', '2018-02-15 22:00:31', 3, 0), (5, 0, 'Helen', 98789798, 'Guatemala', '2018-02-18 10:53:53', 1, 1), (6, 0, 'Juan', 7987987, 'Chimaltenango', '2018-02-18 10:56:44', 1, 0), (7, 798798798, 'Jorge Maldonado', 2147483647, 'Colonia la Flores', '2018-02-18 11:10:07', 1, 1), (8, 0, 'Marta Cabrera', 987987987, 'Guatemala', '2018-02-18 11:11:40', 2, 1), (9, 79879879, 'Julio Estrada', 897987987, 'Avenida Elena', '2018-02-18 11:13:23', 3, 1), (10, 2147483647, 'Roberto Morazan', 2147483647, 'Chimaltenango, Guatemala', '2018-03-04 19:17:22', 1, 1), (11, 898798798, 'Rosa Pineda', 987998788, 'Ciudad Quetzal', '2018-03-04 19:17:45', 1, 1), (12, 0, 'Angel Molina', 2147483647, 'Calzada Buena Vista', '2018-03-04 19:18:21', 1, 1); -- -------------------------------------------------------- -- -- Estructura de tabla para la tabla `detallefactura` -- CREATE TABLE `detallefactura` ( `correlativo` bigint(11) NOT NULL, `nofactura` bigint(11) DEFAULT NULL, `codproducto` int(11) DEFAULT NULL, `cantidad` int(11) DEFAULT NULL, `preciototal` decimal(10,2) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -------------------------------------------------------- -- -- Estructura de tabla para la tabla `detalle_temp` -- CREATE TABLE `detalle_temp` ( `correlativo` int(11) NOT NULL, `nofactura` bigint(11) NOT NULL, `codproducto` int(11) NOT NULL, `cantidad` int(11) NOT NULL, `preciototal` decimal(10,2) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -------------------------------------------------------- -- -- Estructura de tabla para la tabla `entradas` -- CREATE TABLE `entradas` ( `correlativo` int(11) NOT NULL, `codproducto` int(11) NOT NULL, `fecha` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `cantidad` int(11) NOT NULL, `precio` decimal(10,2) NOT NULL, `usuario_id` int(11) NOT NULL DEFAULT '1' ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Volcado de datos para la tabla `entradas` -- INSERT INTO `entradas` (`correlativo`, `codproducto`, `fecha`, `cantidad`, `precio`, `usuario_id`) VALUES (1, 1, '0000-00-00 00:00:00', 150, '110.00', 1), (2, 2, '2018-04-05 00:12:15', 100, '1500.00', 1), (3, 3, '2018-04-07 22:48:23', 200, '250.00', 9), (4, 4, '2018-09-08 22:28:50', 50, '10000.00', 1), (5, 5, '2018-09-08 22:34:38', 100, '500.00', 1), (6, 6, '2018-09-08 22:35:27', 8, '2000.00', 1), (7, 7, '2018-12-02 00:15:09', 75, '2200.00', 1), (8, 8, '2018-12-02 00:39:42', 75, '160.00', 1); -- -------------------------------------------------------- -- -- Estructura de tabla para la tabla `factura` -- CREATE TABLE `factura` ( `nofactura` bigint(11) NOT NULL, `fecha` datetime NOT NULL, `usuario` int(11) DEFAULT NULL, `codcliente` int(11) DEFAULT NULL, `totaltactura` decimal(10,2) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -------------------------------------------------------- -- -- Estructura de tabla para la tabla `producto` -- CREATE TABLE `producto` ( `codproducto` int(11) NOT NULL, `descripcion` varchar(100) DEFAULT NULL, `proveedor` int(11) DEFAULT NULL, `precio` decimal(10,2) DEFAULT NULL, `existencia` int(11) DEFAULT NULL, `date_add` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `usuario_id` int(11) NOT NULL, `estatus` int(11) NOT NULL DEFAULT '1', `foto` text ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Volcado de datos para la tabla `producto` -- INSERT INTO `producto` (`codproducto`, `descripcion`, `proveedor`, `precio`, `existencia`, `date_add`, `usuario_id`, `estatus`, `foto`) VALUES (1, 'Mouse USB', 11, '110.00', 150, '2018-04-05 00:09:34', 1, 1, 'img_producto.png'), (2, 'Monitor LCD', 3, '1500.00', 100, '2018-04-05 00:12:15', 1, 1, 'img_producto.png'), (3, 'Teclado USB', 9, '250.00', 200, '2018-04-07 22:48:23', 9, 1, 'img_producto.png'), (4, 'Cama', 5, '10000.00', 50, '2018-09-08 22:28:50', 1, 1, 'img_21084f55f7b61c8baa2726ad0b4a1dca.jpg'), (5, 'Plancha', 6, '500.00', 100, '2018-09-08 22:34:38', 1, 1, 'img_25c1e2ae283b99e83b387bf800052939.jpg'), (6, 'Monitor', 11, '2000.00', 8, '2018-09-08 22:35:27', 1, 1, 'img_producto.png'), (7, 'Monitor LCD 17', 9, '2200.00', 75, '2018-12-02 00:15:09', 1, 1, 'img_1328286905ecc9eec8e81b94fa1786b9.jpg'), (8, 'USG 32 GB', 11, '160.00', 75, '2018-12-02 00:39:42', 1, 1, 'img_cce86641de32660a29e0fa49f58a950c.jpg'); -- -- Disparadores `producto` -- DELIMITER $$ CREATE TRIGGER `entradas_A_I` AFTER INSERT ON `producto` FOR EACH ROW BEGIN INSERT INTO entradas(codproducto,cantidad,precio,usuario_id) VALUES(new.codproducto,new.existencia,new.precio,new.usuario_id); END $$ DELIMITER ; -- -------------------------------------------------------- -- -- Estructura de tabla para la tabla `proveedor` -- CREATE TABLE `proveedor` ( `codproveedor` int(11) NOT NULL, `proveedor` varchar(100) DEFAULT NULL, `contacto` varchar(100) DEFAULT NULL, `telefono` bigint(11) DEFAULT NULL, `direccion` text, `date_add` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `usuario_id` int(11) NOT NULL, `estatus` int(11) NOT NULL DEFAULT '1' ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Volcado de datos para la tabla `proveedor` -- INSERT INTO `proveedor` (`codproveedor`, `proveedor`, `contacto`, `telefono`, `direccion`, `date_add`, `usuario_id`, `estatus`) VALUES (1, 'BIC', 'Claudia Rosales', 789877889, 'Avenida las Americas', '2018-03-20 23:13:43', 1, 0), (2, 'CASIO', 'Jorge Herrera', 565656565656, 'Calzada Las Flores', '2018-03-20 23:14:41', 2, 0), (3, 'Omega', 'Julio Estrada', 982877489, 'Avenida Elena Zona 4, Guatemala', '2018-03-24 23:21:10', 1, 1), (4, 'Dell Compani', 'Roberto Estrada', 2147483647, 'Guatemala, Guatemala', '2018-03-24 23:21:59', 1, 1), (5, 'Olimpia S.A', 'Elena Franco Morales', 564535676, '5ta. Avenida Zona 4 Ciudad', '2018-03-24 23:22:45', 1, 1), (6, 'Oster', 'Fernando Guerra', 78987678, 'Calzada La Paz, Guatemala', '2018-03-24 23:24:43', 1, 1), (7, 'ACELTECSA S.A', 'Ruben Pérez', 789879889, 'Colonia las Victorias', '2018-03-24 23:25:39', 1, 1), (8, 'Sony', 'Julieta Contreras', 89476787, 'Antigua Guatemala', '2018-03-24 23:26:45', 1, 1), (9, 'VAIO', 'Felix Arnoldo Rojas', 476378276, 'Avenida las Americas Zona 13', '2018-03-24 23:30:33', 1, 1), (10, 'SUMAR', 'Oscar Maldonado', 788376787, 'Colonia San Jose, Zona 5 Guatemala', '2018-03-24 23:32:28', 1, 1), (11, 'HP', 'Angel Cardona', 2147483647, '5ta. calle zona 4 Guatemala', '2018-03-24 23:52:20', 2, 1); -- -------------------------------------------------------- -- -- Estructura de tabla para la tabla `rol` -- CREATE TABLE `rol` ( `idrol` int(11) NOT NULL, `rol` varchar(20) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Volcado de datos para la tabla `rol` -- INSERT INTO `rol` (`idrol`, `rol`) VALUES (1, 'Administrador'), (2, 'Supervisor'), (3, 'Vendedor'); -- -------------------------------------------------------- -- -- Estructura de tabla para la tabla `usuario` -- CREATE TABLE `usuario` ( `idusuario` int(11) NOT NULL, `nombre` varchar(50) DEFAULT NULL, `correo` varchar(100) DEFAULT NULL, `usuario` varchar(15) DEFAULT NULL, `clave` varchar(100) DEFAULT NULL, `rol` int(11) DEFAULT NULL, `estatus` int(11) NOT NULL DEFAULT '1' ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Volcado de datos para la tabla `usuario` -- INSERT INTO `usuario` (`idusuario`, `nombre`, `correo`, `usuario`, `clave`, `rol`, `estatus`) VALUES (1, 'Abel', 'info@abelosh.com', 'admin', '202cb962ac59075b964b07152d234b70', 1, 1), (2, 'Julio Estrada', 'julio@gmail.com', 'julio', 'c027636003b468821081e281758e35ff', 2, 1), (3, 'Carlos Hernández', 'carlos@gmail.com', 'carlos', 'dc599a9972fde3045dab59dbd1ae170b', 3, 1), (5, 'Marta Elena Franco', 'marta@gmail.com', 'marta', 'a763a66f984948ca463b081bf0f0e6d0', 3, 1), (7, 'Carol Cabrera', 'carol@gmail.com', 'carol', 'a9a0198010a6073db96434f6cc5f22a8', 2, 0), (8, 'Marvin Solares ', 'marvin@gmail.com', 'marvin', 'dba0079f1cb3a3b56e102dd5e04fa2af', 3, 1), (9, 'Alan Melgar', 'alan@gmail.com', 'alan', '02558a70324e7c4f269c69825450cec8', 2, 1), (10, 'Efrain Gómez', 'efrain@gmail.com', 'efrain', '69423f0c254e5c1d2b0f5ee202459d2c', 2, 1), (11, 'Fran Escobar', 'fran@gmail.com', 'fran', '2c20cb5558626540a1704b1fe524ea9a', 1, 1), (12, 'Hana Montenegro', 'hana@gmail.com', 'hana', '52fd46504e1b86d80cfa22c0a1168a9d', 3, 1), (13, 'Fredy Miranda', 'fredy@gmail.com', 'fredy', 'b89845d7eb5f8388e090fcc151d618c8', 2, 1), (14, 'Roberto Salazar', 'roberto@hotmail.com', 'roberto', 'c1bfc188dba59d2681648aa0e6ca8c8e', 3, 1), (15, 'William Fernando Pérez', 'william@hotmail.com', 'william', 'fd820a2b4461bddd116c1518bc4b0f77', 3, 1), (16, 'Francisco Mora', 'frans@gmail.com', 'frans', '64dd0133f9fb666ca6f4692543844f31', 3, 1), (17, 'Ruben Guevara', 'ruben@hotmail.es', 'ruben', '32252792b9dccf239f5a5bd8e778dbc2', 3, 1); -- -- Índices para tablas volcadas -- -- -- Indices de la tabla `cliente` -- ALTER TABLE `cliente` ADD PRIMARY KEY (`idcliente`), ADD KEY `usuario_id` (`usuario_id`); -- -- Indices de la tabla `detallefactura` -- ALTER TABLE `detallefactura` ADD PRIMARY KEY (`correlativo`), ADD KEY `codproducto` (`codproducto`), ADD KEY `nofactura` (`nofactura`); -- -- Indices de la tabla `detalle_temp` -- ALTER TABLE `detalle_temp` ADD PRIMARY KEY (`correlativo`), ADD KEY `nofactura` (`nofactura`), ADD KEY `codproducto` (`codproducto`); -- -- Indices de la tabla `entradas` -- ALTER TABLE `entradas` ADD PRIMARY KEY (`correlativo`), ADD KEY `codproducto` (`codproducto`); -- -- Indices de la tabla `factura` -- ALTER TABLE `factura` ADD PRIMARY KEY (`nofactura`), ADD KEY `usuario` (`usuario`), ADD KEY `codcliente` (`codcliente`); -- -- Indices de la tabla `producto` -- ALTER TABLE `producto` ADD PRIMARY KEY (`codproducto`), ADD KEY `proveedor` (`proveedor`), ADD KEY `usuario_id` (`usuario_id`); -- -- Indices de la tabla `proveedor` -- ALTER TABLE `proveedor` ADD PRIMARY KEY (`codproveedor`), ADD KEY `usuario_id` (`usuario_id`); -- -- Indices de la tabla `rol` -- ALTER TABLE `rol` ADD PRIMARY KEY (`idrol`); -- -- Indices de la tabla `usuario` -- ALTER TABLE `usuario` ADD PRIMARY KEY (`idusuario`), ADD KEY `rol` (`rol`); -- -- AUTO_INCREMENT de las tablas volcadas -- -- -- AUTO_INCREMENT de la tabla `cliente` -- ALTER TABLE `cliente` MODIFY `idcliente` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13; -- -- AUTO_INCREMENT de la tabla `detallefactura` -- ALTER TABLE `detallefactura` MODIFY `correlativo` bigint(11) NOT NULL AUTO_INCREMENT; -- -- AUTO_INCREMENT de la tabla `detalle_temp` -- ALTER TABLE `detalle_temp` MODIFY `correlativo` int(11) NOT NULL AUTO_INCREMENT; -- -- AUTO_INCREMENT de la tabla `entradas` -- ALTER TABLE `entradas` MODIFY `correlativo` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9; -- -- AUTO_INCREMENT de la tabla `factura` -- ALTER TABLE `factura` MODIFY `nofactura` bigint(11) NOT NULL AUTO_INCREMENT; -- -- AUTO_INCREMENT de la tabla `producto` -- ALTER TABLE `producto` MODIFY `codproducto` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9; -- -- AUTO_INCREMENT de la tabla `proveedor` -- ALTER TABLE `proveedor` MODIFY `codproveedor` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12; -- -- AUTO_INCREMENT de la tabla `rol` -- ALTER TABLE `rol` MODIFY `idrol` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; -- -- AUTO_INCREMENT de la tabla `usuario` -- ALTER TABLE `usuario` MODIFY `idusuario` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=18; -- -- Restricciones para tablas volcadas -- -- -- Filtros para la tabla `cliente` -- ALTER TABLE `cliente` ADD CONSTRAINT `cliente_ibfk_1` FOREIGN KEY (`usuario_id`) REFERENCES `usuario` (`idusuario`); -- -- Filtros para la tabla `detallefactura` -- ALTER TABLE `detallefactura` ADD CONSTRAINT `detallefactura_ibfk_2` FOREIGN KEY (`codproducto`) REFERENCES `producto` (`codproducto`), ADD CONSTRAINT `detallefactura_ibfk_3` FOREIGN KEY (`nofactura`) REFERENCES `factura` (`nofactura`) ON DELETE CASCADE ON UPDATE CASCADE; -- -- Filtros para la tabla `detalle_temp` -- ALTER TABLE `detalle_temp` ADD CONSTRAINT `detalle_temp_ibfk_1` FOREIGN KEY (`nofactura`) REFERENCES `factura` (`nofactura`) ON DELETE CASCADE ON UPDATE CASCADE, ADD CONSTRAINT `detalle_temp_ibfk_2` FOREIGN KEY (`codproducto`) REFERENCES `producto` (`codproducto`) ON DELETE CASCADE ON UPDATE CASCADE; -- -- Filtros para la tabla `entradas` -- ALTER TABLE `entradas` ADD CONSTRAINT `entradas_ibfk_1` FOREIGN KEY (`codproducto`) REFERENCES `producto` (`codproducto`) ON DELETE CASCADE ON UPDATE CASCADE; -- -- Filtros para la tabla `factura` -- ALTER TABLE `factura` ADD CONSTRAINT `factura_ibfk_2` FOREIGN KEY (`codcliente`) REFERENCES `cliente` (`idcliente`), ADD CONSTRAINT `factura_ibfk_3` FOREIGN KEY (`usuario`) REFERENCES `usuario` (`idusuario`) ON DELETE CASCADE ON UPDATE CASCADE; -- -- Filtros para la tabla `producto` -- ALTER TABLE `producto` ADD CONSTRAINT `producto_ibfk_1` FOREIGN KEY (`proveedor`) REFERENCES `proveedor` (`codproveedor`), ADD CONSTRAINT `producto_ibfk_2` FOREIGN KEY (`usuario_id`) REFERENCES `usuario` (`idusuario`) ON DELETE CASCADE ON UPDATE CASCADE; -- -- Filtros para la tabla `proveedor` -- ALTER TABLE `proveedor` ADD CONSTRAINT `proveedor_ibfk_1` FOREIGN KEY (`usuario_id`) REFERENCES `usuario` (`idusuario`) ON DELETE CASCADE ON UPDATE CASCADE; -- -- Filtros para la tabla `usuario` -- ALTER TABLE `usuario` ADD CONSTRAINT `usuario_ibfk_1` FOREIGN KEY (`rol`) REFERENCES `rol` (`idrol`) ON DELETE CASCADE ON UPDATE CASCADE; COMMIT; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
cual es el error??? Votos: 0 - Respuestas: 5 - Vistas: 5 Compartir en: Google Facebook Twitter LinkedIn Link
Respuestas:
-
Fecha: 09-04-2020 13:12:47 Hola Pilar,
Por favor utiliza los BBCode para darle formato a tu pregunta y sea más fácil ayudarte. Votos: 0 - Link respuesta -
Fecha: 10-04-2020 18:59:12 lo probe regirstrando en el cmd
con esta sintaxis y registro insert into cliente values (null,45,"camilo",4465,"calle3",1997,1,1);
estos datos corresponde a la tabla cliente:
idcliente,nit,nombre,telefono,direccion,dateadd,usuario_id,estatus
Así esta en la base de datos tal cual pero el formulario tengo un conflicto al acutalizarlo con el formulario Votos: 0 - Link respuesta -
Fecha: 11-04-2020 18:36:26 probe desde el sql esta sintaxis si registro en phpmyadmin
INSERT INTO `cliente`(`nit`, `nombre`, `telefono`, `direccion`, `usuario_id`) VALUES (1,'1212',11123,'ggg',1);
y en el formulario la cambie asi
$query_insert = mysqli_query($conection,"INSERT INTO `cliente`(`nit`,`nombre`,`telefono`,`direccion`,`usuario_id`)
VALUES('$nit,'$nombre','$telefono','$direccion','$usuario_id')");
y nada me dice
error : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'asda','123213','21312','')' at line 2
no llega el usuario id y encima el nit tampoco Votos: 0 - Link respuesta -
Fecha: 13-04-2020 04:21:35 OLa,
creo que tienes que elegir una llave forranea correcta y dentro de phpmyadmin... intentar insertar registros antes de hacerlo con el formulario . si no se guardan los registros en phpmyadmin ,busca forma de elegir una clave forranea correcta .. creo que estas teniedo problemas con tus tablas debido a una mala relacion . Votos: 0 - Link respuesta -
Fecha: 13-04-2020 23:45:06 registra normal en phpmyadmin
pero en el formulario no registra , pero no entiendo en el cmd y phpmyadmin si .
puede ser la relacion o los indices o tambien conocidos como llaves foraneas Votos: 0 - Link respuesta
Para participar activamente de la comunidad primero debes autenticarte, ingresa al sistema.Iniciar Sesión
