Ver Mensaje Individual
  #6 (permalink)  
Antiguo 15/04/2009, 20:42
Avatar de kimmy
kimmy
 
Fecha de Ingreso: julio-2008
Mensajes: 841
Antigüedad: 15 años, 9 meses
Puntos: 15
Respuesta: Guardar datos de select multiples en bd

Este es la pagina donde está el form con el javascript:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
<script language="JavaScript" type="text/JavaScript">
<!--
var categoria = new Array()
categoria[1] = ["elige subcategoría...","Bebé","Niña","Niño","Mujer","Hom bre"]

var producto = new Array()
producto[1] = new Array()
producto[1][1] = ["elige item","Vestidos","Conjuntos","Monitos","Pantalones ","Franelas","Zapatos","Otros "]
producto[1][2] = ["elige item","Vestidos","Conjuntos","Monos","Pantalones", "Faldas","Franelas","Trajes de Baño","Ropa Interior","Zapatos"]
producto[1][3] = ["elige item","Conjuntos","Monos","Pantalones","Shorts y Bermudas","Camisas","Franelas","Trajes de Baño","Ropa Interior","Zapatos"]
producto[1][4] = ["elige item","Vestidos","Blusas y Franelas","Pantalones y Short","Chaquetas","Pijamas","Ropa Interior","Trajes de Baño","Zapatos"]
producto[1][5] = ["elige item","Franelas","Camisas","Pantalones","Chaquetas y Sweaters","Short y Bermudas","Ropa Interior","Zapatos"]

function ponCategorias(formu)
{ var elTipo = formu.tipo.selectedIndex
formu.categorias.length = categoria[elTipo].length
for (i=0; i<formu.categorias.length; i++)
{ formu.categorias.options[i].text = categoria[elTipo][i]
}
}

function ponProducto(formu)
{ var elTipo = formu.tipo.selectedIndex
var laCategoria = formu.categorias.selectedIndex
formu.producto.length = producto[elTipo][laCategoria].length
for (i=0; i<formu.producto.length; i++)
{ formu.producto.options[i].text = producto[elTipo][laCategoria][i]
}
}

var tallitas = new Array()
tallitas[1] = ["elige subcategoría...","Ropa"]
tallitas[2] = ["elige subcategoría...","Ropa","Zapatos"]
tallitas[3] = ["elige subcategoría...","Blusas y Franelas","Pantalones","Conjuntos","Trajes de Baño","Panties","Brassier","Zapatos"]
tallitas[4] = ["elige subcategoría...","Camisas y Franelas","Pantalones","Ropa Interior","Zapatos"]

var tallas = new Array()
tallas[1] = new Array()
tallas[1][1] = ["elige talla","0-3M","3-6M","6-9M","9-12M","12-24M"]

tallas[2] = new Array()
tallas[2][1] = ["elige talla","2","3","4","5","6","7","8","9","10","11"," 12","13","14","15","16"]
tallas[2][2] = ["elige talla","17","18","19","20","21","22","23","24","25 ","26","27","28","29","30","31","32","33"]

tallas[3] = new Array()
tallas[3][1] = ["elige talla","SS","S","M","L","XL"]
tallas[3][2] = ["elige talla","26","28","30","32","34","36","38","40"]
tallas[3][3] = ["elige talla","SS","S","M","L","XL"]
tallas[3][4] = ["elige talla","SS","S","M","L","XL"]
tallas[3][5] = ["elige talla","SS","S","M","L","XL"]
tallas[3][6] = ["elige talla","30A","30B","32A","32B","34A","36A","36B"," 38A","38B","40A","40B"]
tallas[3][7] = ["elige talla","34","35","36","37","38","39","40","41","42 ","43","44","45"]

tallas[4] = new Array()
tallas[4][1] = ["elige talla","S","M","L","XL","2XL"]
tallas[4][2] = ["elige talla","26","28","30","32","34","36","38","40","42 "]
tallas[4][3] = ["elige talla","S","M","L","XL","2XL"]
tallas[4][4] = ["elige talla","36","37","38","39","40","41","42","43","44 ","45","46"]

function ponTallas(formu)
{ var laTallon = formu.tallon.selectedIndex
formu.tallita.length = tallitas[laTallon].length
for (i=0; i<formu.tallita.length; i++)
{ formu.tallita.options[i].text = tallitas[laTallon][i]
}
}
function ponTalla(formu)
{ var laTallon = formu.tallon.selectedIndex
var laTallita = formu.tallita.selectedIndex
formu.talla.length = tallas[laTallon][laTallita].length
for (i=0; i<formu.talla.length; i++)
{ formu.talla.options[i].text = tallas[laTallon][laTallita][i]
}
}

</SCRIPT>
</head>
<body>
<FORM action="guardar.php" method='post' enctype="multipart/form-data" name="formu" id="formu">
<table width="586" border="0" cellspacing="2" cellpadding="2">
<tr bgcolor="#0066CC">
<th colspan="10" scope="row"><span class="Estilo23">CARGAR PRODUCTOS </span></th>
</tr>
<tr>
<th bgcolor="#66CCFF" class="Estilo10" scope="row"><div align="justify" class="Estilo27">Fecha:</div></th>
<td colspan="9"><input name="fecha" readonly="true" type="text" id="fecha" value="<?php echo date('Y-m-d H:i:s');?>">
</td>
</tr>
<tr>
<th width="140" bgcolor="#66CCFF" scope="row"><div align="justify" class="Estilo10">Categor&iacute;a:</div></th>
<td colspan="9"><select name="tipo" onChange="ponCategorias(this.form)">
<option>elige categor&iacute;a...</option>
<option>Ropa</option>
</select></td>
</tr>
<tr>
<th bgcolor="#66CCFF" scope="row"><div align="justify" class="Estilo10">Subcategor&iacute;a:</div></th>
<td colspan="9"><select name="categorias" id="categorias" onChange="ponProducto(this.form)">
<option></option>
</select></td>
</tr>
<tr>
<th bgcolor="#66CCFF" scope="row"><div align="justify" class="Estilo10">Item:</div></th>
<td colspan="9"><select name="producto">
<option></option>
</select></td>
</tr>
<tr>
<th bgcolor="#66CCFF" scope="row"><div align="justify" class="Estilo27"><span class="Estilo26">Nombre Producto: </span></div></th>
<td colspan="9">
<div align="justify">
<input name="nombre_prod" type="text" id="nombre_prod" size="60">
<br>
(M&aacute;ximo 60 caracteres) </div></td>
</tr>
<tr>
<th bgcolor="#66CCFF" scope="row"><div align="justify" class="Estilo10">Cantidad:</div></th>
<td colspan="9"> <input name="ctdad" type="text" id="ctdad" size="5"></td>
</tr>
<tr>
<th bgcolor="#66CCFF" scope="row"><div align="justify" class="Estilo10">Categor&iacute;a Talla :</div></th>
<td colspan="9">
<div align="justify">
<select name="tallon" id="tallon" onChange="ponTallas(this.form)">
<option>elige categor&iacute;a...</option>
<option selected>Beb&eacute;</option>
<option>Ni&ntilde;os</option>
<option>Mujer</option>
<option>Hombre</option>
</select>
</div> <div align="center">
</div> <div align="center">
</div> <div align="center"></div> <div align="center">
</div> <div align="center"></div> <div align="center"></div> <div align="center">
</div></td>
</tr>
<tr>
<th bgcolor="#66CCFF" scope="row"><div align="justify" class="Estilo10">Subcategor&iacute;a Talla: </div></th>
<td colspan="9"><select name="tallita" id="select4" onChange="ponTalla(this.form)">
</select></td>
</tr>
<tr>
<th bgcolor="#66CCFF" scope="row"><div align="justify" class="Estilo10">Talla:</div></th>
<td colspan="9"><select name="talla" size="2" multiple>
</select></td>
</tr>
<tr bgcolor="#0066CC">
<th colspan="10" scope="row"><div align="center"></div><div align="center">
<input name="atras" type="button" id="atras" value="Atr&aacute;s" onClick="history.back();">
-
<input type="submit" name="Submit" value="Enviar">
-
<input name="Borrar" type="reset" id="Borrar" value="Borrar">
</div></th>
</tr>
</table>
</form>
</body>
</html>

Y este es el que recibe (guardar.php):

<?
session_start();
$_SESSION['x'] = $x;
// incluye los archivos de función para esta aplicación
require_once("funciones.php");
$fecha = $_POST['fecha'];
$tipo = $_POST['tipo'];
$categorias = $_POST['categorias'];
$producto = $_POST['producto'];
$nombre_prod = $_POST['nombre_prod'];
$ctdad = $_POST['ctdad'];
$tallon = $_POST['tallon'];
$tallita = $_POST['tallita'];
$talla = $_POST['talla'];

$conexion = db_connect();
if (!$conexion)
return 0;

$sql= "INSERT INTO articulos (fecha, tipo, categorias, producto, nombre_producto, ctdad, tallon, tallita, talla) " .
"VALUES ('$fecha', '$tipo', '$categorias', '$producto', '$nombre_producto', '$ctdad', '$tallon', '$tallita', '$talla')";
$res = mysql_query($sql) or die ( "Error MySQL dice: " . mysql_error() );

$consultar = mysql_query("SELECT cod_articulo FROM articulos WHERE nombre_producto='$nombre_producto'");
while ($registro = mysql_fetch_array($consultar)) {
$cod_articulo = $registro["cod_articulo"];

}
for ($i=0;$i<count($talla);$i++)
{
mysql_query("INSERT INTO talla (talla) VALUES (".$talla[$i].") WHERE nombre_producto='$nombre_producto'");
}
?>

Gracias...