Les cuento, mi problema es que tengo un código con campos dinámicos en javascript, es esta:
<html>
<head>
<title>Crear Campo de texto</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
icremento =0;
function crear(obj) {
icremento++;
field = document.getElementById('field');
contenedor = document.createElement('div');
contenedor.id = 'div'+icremento;
field.appendChild(contenedor);
boton = document.createElement('input');
boton.type = 'text';
boton.name = 'h'+'[]';
contenedor.appendChild(boton);
boton = document.createElement('input');
boton.type = 'text';
boton.name = 'p'+'[]';
contenedor.appendChild(boton);
boton = document.createElement('input');
boton.type = 'text';
boton.name = 'q'+'[]';
contenedor.appendChild(boton);
boton = document.createElement('input');
boton.type = 'button';
boton.value = 'Borrar';
boton.name = 'div'+icremento;
boton.onclick = function () {borrar(this.name)}
contenedor.appendChild(boton);
}
function borrar(obj) {
field = document.getElementById('field');
field.removeChild(document.getElementById(obj));
}
</script>
</head>
<body>
<form name="form1" method="POST" action="prueba.php">
<fieldset id="field">
<input type="button" value="Crear caja de texto" onClick="crear(this)">
<input name="save" type="submit" value="Guardar" onClick="enviar(this)">
</fieldset>
</form>
</body>
</html>
tengo otra página que recoge los datos enviados por el array que se genera
y los inserta en la base de datos que es esta:
Código PHP:
<?php require_once('../Connections/conexion.php'); ?>
<?php
foreach($_POST['h'] as $key=>$value)
{
echo mysql_select_db($database_conexion, $conexion);
echo mysql_query("INSERT INTO planifi_insum (id_insumo) VALUES('$value')",$conexion)or die(mysql_error());
}
foreach($_POST['p'] as $key=>$value)
{
echo mysql_select_db($database_conexion, $conexion);
echo mysql_query("INSERT INTO planifi_insum (nombre_insumos) VALUES('$value')",$conexion)or die(mysql_error());
}
foreach($_POST['q'] as $key=>$value)
{
echo mysql_select_db($database_conexion, $conexion);
echo mysql_query("INSERT INTO planifi_insum (cantidad) VALUES('$value')",$conexion)or die(mysql_error());
}
?>
38 3
37 2 0
36 1 0
Me gustaría que me ayudaran para que los datos se ingresen así:
38 1 2 3
39 2 3 4
Agradecería toda la ayuda que me pudieran brindar.