Ver Mensaje Individual
  #9 (permalink)  
Antiguo 11/04/2016, 10:44
Avatar de aviweb2015
aviweb2015
 
Fecha de Ingreso: abril-2016
Ubicación: venezuela
Mensajes: 215
Antigüedad: 8 años, 1 mes
Puntos: 1
Respuesta: for no deja ingresar dos prudoctos

pero como adapto eso a esto

Código PHP:
Ver original
  1. $cuenta = count($_POST['id_prod']);
  2.  
  3. // guardamos la factura en la tabla:
  4.  
  5. $a = $db->query("INSERT INTO tabla (campo, campo) VALUES('valor','valor')");
  6.  
  7.  
  8. //luego iniciamos el for para la tabla detalle:
  9.  
  10. for($i=0; $i<$cuenta; $i++){
  11.  
  12. //preparamos las variables que llegan:
  13.  
  14. $id = $_POST['id_pro'][$i];
  15. $fact = $_POST['factura'];//numero previamente generado
  16. $codi = $_POST['codigo'][$i];
  17. $item = $_POST['item'][$i];
  18. $canti = $_POST['cantidad'][$i];
  19. $costo = $_POST['costo'][$i];
  20.  
  21.  
  22. $b = $db->query("INSERT INTO detalle (campo, campo, campo...) VALUES ('valor','valor','valor'...)");
  23.  
  24. }


a esto





Código PHP:
Ver original
  1. <?php
  2. include("conexion.php");
  3. if (isset ($_POST['guardar'])){
  4. $idfactura=$_POST['idfactura'];
  5. $idcedula=$_POST['idcedula'];
  6. $fecha=$_POST['fecha'];
  7. $costetotal=$_POST['costetotal'];
  8. $iddetalle_factura=$_POST['iddetalle_factura'];
  9. $idproductos=$_POST['idproductos'];
  10. $cantprod=$_POST['chk_group3'];
  11. $coste=$_POST['chk_group2'];
  12. $personas=$_POST['personas'];
  13. $evento=$_POST['evento'];
  14. $lugar_evento=$_POST['lugar_evento'];
  15. $dia=$_POST['dia'];
  16. $hora_evento=$_POST['hora_evento'];
  17.  
  18.  
  19.   $sql="SELECT * FROM factura WHERE idfactura='$idfactura'";
  20.   $res=mysql_query($sql,$link);
  21.   $nrows=mysql_num_rows($res);
  22.   if($nrows==0){
  23.  
  24.  
  25.         for($j=0;$j<count($cantprod);$j++){
  26.         for($k=0;$k<count($coste);$k++){
  27.  
  28.  
  29.  
  30. if (mysql_query("INSERT INTO factura (idfactura,idcedula,fecha,costetotal) VALUES
  31. ('$idfactura','$idcedula','$fecha','$costetotal')",$link));
  32.  
  33. if (mysql_query("INSERT INTO detalles_factura (iddetalle_factura,idfactura,idproductos,cantprod,coste,personas,evento,lugar_evento,dia,hora_evento) VALUES
  34. ('$iddetalle_factura','$idfactura','$idproductos','$cantprod[$j]','$coste[$k]','$personas','$evento','$lugar_evento','$dia','$hora_evento')",$link));
  35. }}
  36.  
  37. echo "<script>alert ('Se ha generado el contrato!');</script>
  38. <META HTTP-EQUIV='REFRESH' CONTENT=0;URL=http:presupuesto.php>";
  39.           }
  40.   else echo "<script>alert ('Disculpe este presupuesto ya existe!');</script>
  41. <META HTTP-EQUIV='REFRESH' CONTENT=0;URL=http:presupuesto.php>";
  42. }
  43. ?>
__________________
yoclens avilan