Ver Mensaje Individual
  #3 (permalink)  
Antiguo 04/07/2015, 14:01
pandora09
 
Fecha de Ingreso: julio-2015
Mensajes: 16
Antigüedad: 8 años, 10 meses
Puntos: 1
Respuesta: Problemas con Insert de id en tabla factura_detalle

Buenas tardes gnzsoloyo, gracias por responder.

Hice el cambio que me comentaste pero sigue sin funcionar.. me inserta los datos de cabecera en la tabla factura_datos pero solo me ingresa el primer servicio en la tabla factura detalle y me arroja el siguiente mensaje al momento de hacer ese segundo insert:

Error en la Conexión a la Tabla Factura_Detalle

El codigo con la correcion ha quedado asi:

Código PHP:
Ver original
  1. <?
  2.  include('conexionbd.php');
  3. //Declarando Variables
  4.  $cedula=$_POST['cedula'];
  5.  $fecha=$_POST['fecha'];
  6.  $hora=$_POST['hora'];
  7.  $codigo=$_POST['codigo'];
  8.  $forma_pago=$_POST['forma_p'];
  9.  $total=$_POST['total'];
  10.  $accion=$_POST['accion'];
  11.  $servicio= array();
  12.  $cantidad= array();
  13.  $preciounit= array();
  14.  $totalitem=array();
  15.  
  16. foreach($_POST['servicio'] as $key=>$value)
  17.     $servicio[]= $value;
  18.  
  19. foreach($_POST['cantidad'] as $key=>$value)
  20.     $cantidad[]= $value;
  21.  
  22. foreach($_POST['preciounit'] as $key=>$value)
  23.     $preciounit[]= $value;
  24.  
  25. foreach($_POST['totalitem'] as $key=>$value)
  26.     $totalitem[]= $value;
  27.  
  28.  if ($_POST[Registrar_Factura]) {
  29.  include('conexionbd.php');
  30.  $hora=gmdate('H:i:s', time() - 16200);
  31.  $sql="INSERT INTO factura_datos (cedula,fecha,hora,forma_p,total) VALUES
  32.       ('".$cedula."','".$fecha."','".$hora."','".$forma_pago."','".$total."')";
  33.  $result=mysql_query($sql) or die ("Error en la Conexión a la Tabla Factura_Datos");
  34.  //SELECCIONO EL ULTIMO ID INGRESADO DE LA TABLA FACTURA_DATOS
  35.  $ultimo_id=mysql_insert_id($conexion);
  36.  for($i=0; $i<count($servicio); $i++)
  37.             {
  38.  //INGRESO LOS DATOS EN LA TABLA FACTURA_DETALLE
  39.  $sql1="INSERT INTO factura_detalle (fact_nro,descripcion,cant,precio,sub_t) VALUES
  40.       ('$ultimo_id','".$servicio[$i]."','".$cantidad[$i]."','".$preciounit[$i]."','".$totalitem[$i]."')";
  41.  $resul= mysql_query($sql1)  or die ("Error en la Conexión a la Tabla Factura_Detalle");
  42.            }
  43.  ?><script>alert("Factura Registrada con Exito"); document.location = 'facturacion.php';</script><?
  44.  }
  45.  ?>