Ver Mensaje Individual
  #3 (permalink)  
Antiguo 17/06/2016, 16:11
ycaires
 
Fecha de Ingreso: septiembre-2015
Ubicación: caracas
Mensajes: 75
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: Creación multiples registros por un solo insert

Saludos Jlopez2014
chequea esto es un insert de multiples registros te mando el archivo input y el de proceso, creo que esto es lo que buscar quita los controles que realizan los calculos que no te interesa dicha parte y aplica lo relativo a la carga de solo los campos que nombras, espero que sea algo como esto suerte, revisa ya que hay dos insert uno de la persona que registra y el otros es de la data el que te interesa ha menos que te interesen los dos

////////////////////// input.php


<?PHP
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>FORMULARIO DINAMICO</title>
<meta name= "viewport" content= "width=device-width, user-scalable=no, initial-scale=1.0, maximun-scale=1.0, minimun-scale=1.0">

<link rel="stylesheet" href="ccs/bootstrap.min.css">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">

<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>


</head>

<body>
<div class="container">
<form action="procesar.php" method="post">

<div class= "box box-primary">
<div class="box-header">
<h3 class="box-title">Invoice</h3>
</div>
<div class="box-body">
<div class="form-group">
ReceptName
<input type="text" name="re_name" class="form-control ">
</div>

<div class="form-group">
Location
<input type="text" name="location" class="form-control">
</div>
</div>
<input type="submit" class="btn btn-primary" name="save" value="Guiardar Registro">

</div><br/>


<table class="table table-bordered table-hover">

<thead>
<tr>
<th>No</th>
<th>ProductName</th>
<th>Quantity</th>
<th>Price</th>
<th>Discount</th>
<th>Ammount</th>
<th><input type="button" value="+" id="add" class="btn btn-primary"></th>
</tr>
</thead>

<tbody class="detail">
<tr>
<td class="no">1</td>
<td><input type="text" class="form-control productname" name="productname[]"></td>
<td><input type="text" class="form-control quantity" name="quantity[]"></td>
<td><input type="text" class="form-control price" name="price[]"></td>
<td><input type="text" class="form-control discount" name="discount[]"></td>
<td><input type="text" class="form-control amount" name="amount[]"></td>
<td><a href="#" class="remove">Delete</a></td>
</tr>
</tbody>


<tfoot>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<td colspan="1" align="right"><strong>Total:</strong></td>
<td colspan="5"><strong>$<b class="total"></b></strong></td>
</tr>
</tfoot>

</table>
</form>
</div>


<script src="js/jquery.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>
</html>

<script type="text/javascript">
$(function(){
$('#add').click(function(){
addnewrow();
});

$('body').delegate(' .remove' , 'click' ,function(){
$(this).parent().parent().remove();
});

$(' .detail').delegate(' .quantity,.price,.discount','keyup' ,function(){
var tr = $(this).parent().parent();
var qty = tr.find(' .quantity').val();
var price = tr.find(' .price').val();
var dis = tr.find(' .discount').val();
var amt = (qty * price) - (qty * price * dis)/100;
var text="$"
tr.find(' .amount').val(amt);
total()
});

});

function total()
{
var t = 0;
$('.amount').each(function(i,e)

{
var amt = $(this).val()-0;
t += amt;

});

$('.total').html(t);
}



function addnewrow()
{
var n= ($('.detail tr').length-0)+1;
var tr= '<tr>' +
'<td class="no">' + n + '</td>' +
'<td><input type="text" class="form-control productname" name="productname[]"></td>' +
'<td><input type="text" class="form-control quantity" name="quantity[]"></td>' +
'<td><input type="text" class="form-control price" name="price[]"></td>' +
'<td><input type="text" class="form-control discount" name="discount[]"></td>' +
'<td><input type="text" class="form-control amount" name="amount[]"></td>' +
'<td><a href="#" class="remove">Delete</td>' +
'</tr>';
$('.detail').append(tr);
}
</script>

/////////////// procesar.php


<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

<?php

$server = "localhost";
$usuario = "root";
$contraseña = "";
$bd = "inv";


$conexion = mysqli_connect($server,$usuario,$contraseña,$bd)
or die ("error en conexión favor verificar la conexión");

$insertar = "INSERT INTO tbl_order (re_name,location) VALUES ('{$_POST['re_name']}',' {$_POST['location']}')";

$resultado = mysqli_query($conexion,$insertar)
or die ('erro al insertar ');

$id=mysqli_insert_id($conexion);



for($i = 0 ;$i < count($_POST['productname']);$i++)
{
$insertar = "INSERT INTO tbl_orderdetail SET order_id = '{$id}',product_name='{$_POST['productname'][$i]}',quantity='{$_POST['quantity'][$i]}',price='{$_POST['price'][$i]}',discount='{$_POST['discount'][$i]}',amount='{$_POST['amount'][$i]}' ";

$resultado = mysqli_query($conexion,$insertar)
or die ('erro al insertar ');

}


?>
__________________
ymanol caires z