Foros del Web » Programando para Internet » PHP »

Checkbox

Estas en el tema de Checkbox en el foro de PHP en Foros del Web. Estuve mirando por los foros y encontré el tema que estaba buscando, pero no se como pasar los valores de los checkbox a un carrito ...
  #1 (permalink)  
Antiguo 02/06/2013, 12:36
 
Fecha de Ingreso: diciembre-2008
Ubicación: Madrid
Mensajes: 6
Antigüedad: 15 años, 4 meses
Puntos: 0
Checkbox

Estuve mirando por los foros y encontré el tema que estaba buscando, pero no se como pasar los valores de los checkbox a un carrito de la compra.
De una base de datos saco el nombre, precio y curso, dinámicamente y cada fila tiene un checkbox.
Gracias a los tutos vuestros conseguí que un valor de ellos en este caso el de nombre, me los mandaba a otra página. Pero no se meterlos en el carrito.
Si alguien puede echarme una mano se lo agradecería.
Gracias.
  #2 (permalink)  
Antiguo 02/06/2013, 13:20
Avatar de repara2  
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: Checkbox

Para empezar deberías postear el código que te da problemas, es imposible imaginar una solución.
Salu2
__________________
Fere libenter homines, id quod volunt, credunt.
  #3 (permalink)  
Antiguo 03/06/2013, 07:57
 
Fecha de Ingreso: diciembre-2008
Ubicación: Madrid
Mensajes: 6
Antigüedad: 15 años, 4 meses
Puntos: 0
Respuesta: Checkbox

Saludos, repar2, gracias por leer mi pregunta es verdad, necesitas el codigo perdon,
te lo pongo:
<form action="carro_sin_iva.php" method="post" name="form1" id="form1">
<table width="100%" border="1">
<tr>
<td width="32%"><strong class="letras">Nombre</strong></td>
<td width="33%" align="center"><strong class="letras">Editorial</strong></td>
<td width="25%"><strong class="letras">Precio</strong></td>
<td width="10%"><strong class="letras">Reservar</strong></td>
</tr>
<?php do { ?>
<tr class="letras">
<td><?php echo $row_DatosProductos['strNombre']; ?></td>
<td align="center"><?php echo $row_DatosProductos['editorial']; ?></td>
<td align="center"><?php echo $row_DatosProductos['dblPrecio']; ?> €</td>
<td align="center">
<input name="$carrito_mio[]" type="checkbox" id="checkbox" value="<?php echo $row_DatosProductos['strNombre']; ?>" checked="checked"/>
<label for="checkbox"></label>
<input name="cantidad" type="hidden" id="cantidad" value="1" />
<input name="dblPrecio" type="hidden" id="dblPrecio" value="<?php echo $row_DatosProductos['dblPrecio']; ?>" />
<input name="strNombre" type="hidden" id="strNombre" value="<?php echo $row_DatosProductos['strNombre']; ?>" /></td>
</tr>
<?php } while ($row_DatosProductos = mysql_fetch_assoc($DatosProductos)); ?>
</table><p><label>
<input type="submit" name="Submit" value="Reservar" />
</label></p>
</form>

Y aqui mi problema, mando esto a la pagina carro_sin_iva.php pero no se como implementarlo al carrito, o como se diga, poniendo este otro codigo en dicha pagina:

<?php foreach ($_POST['$carrito_mio'] as $strNombre){
echo $strNombre."<br>";
}
?>
Veo el nombre de los libros seleccionados pero no se como hacer para que integren en el carro.
Muchas gracias.
Habras observado que no tengo mucha experiencia.
Saludos.
  #4 (permalink)  
Antiguo 03/06/2013, 08:14
Avatar de repara2  
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: Checkbox

Veo el nombre de los libros seleccionados pero no se como hacer para que integren en el carro. la pregunta es, tienes un módulo de carro de compra implementado? y cómo funciona? Está claro que puedes enviar datos de una página a otra pero "integrar" productos en el carrito requiere primero tener el módulo funcionando. En el caso que lo tengas, tendrás nuevamente que postear el código, etc. Te recomiendo una búsqueda en Google para ver cómo se puede hacer pero si no estás muy metido en el tema programación será muy difícil obtener resultados. Salu2
__________________
Fere libenter homines, id quod volunt, credunt.
  #5 (permalink)  
Antiguo 03/06/2013, 08:26
 
Fecha de Ingreso: diciembre-2008
Ubicación: Madrid
Mensajes: 6
Antigüedad: 15 años, 4 meses
Puntos: 0
Respuesta: Checkbox

Jo muchas gracias de antemano por tu rapidez. Sino te importa te mando el codigo del carro es este:
<?php require_once('Connections/sumar.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_sumar, $sumar);
$query_Recordset1 = "SELECT * FROM `berriz`";
$Recordset1 = mysql_query($query_Recordset1, $sumar) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$query_Recordset1 = "SELECT * FROM berriz";
$Recordset1 = mysql_query($query_Recordset1, $sumar) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
session_start();
if(isset($_SESSION['carrito']) || isset($_POST['strNombre'])){
if(isset($_SESSION['carrito'])){
$carrito_mio=$_SESSION['carrito'];
if(isset($_POST['strNombre'])){
$strNombre=$_POST['strNombre'];
$dblPrecio=$_POST['dblPrecio'];
$cantidad=$_POST['cantidad'];
$donde=-1;
for($i=0;$i<=count($carrito_mio)-1;$i ++){
if($strNombre==$carrito_mio[$i]['strNombre']){
$donde=$i;
}
}
if($donde != -1){
$cuanto=$carrito_mio[$donde]['cantidad'] + $cantidad;
$carrito_mio[$donde]=array("strNombre"=>$strNombre,"dblPrecio"=>$dblPr ecio,"cantidad"=>$cuanto);
}else{
$carrito_mio[]=array("strNombre"=>$strNombre,"dblPrecio"=>$dblPr ecio,"cantidad"=>$cantidad);
}
}
}else{
$strNombre=$_POST['strNombre'];
$dblPrecio=$_POST['dblPrecio'];
$cantidad=$_POST['cantidad'];
$carrito_mio[]=array("strNombre"=>$strNombre,"dblPrecio"=>$dblPr ecio,"cantidad"=>$cantidad);
}
if(isset($_POST['cantidad2'])){
$id=$_POST['id'];
$cuantos=$_POST['cantidad2'];
if($cuantos<1){
$carrito_mio[$id]=NULL;
}else{
}
$carrito_mio[$id]['cantidad']=$cuantos;
}
if(isset($_POST['id2'])){
$id=$_POST['id2'];
$carrito_mio[$id]=NULL;
}
$_SESSION['carrito']=$carrito_mio;
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

Y sigue asi:

<table width="96%" border="0" align="center">
<tr>
<td width="49%" height="18" align="center" style="font-weight: bold">Nombre del producto</td>
<td width="11%" align="center" style="font-weight: bold">Precio</td>
<td width="18%" align="center" style="font-weight: bold">Cantidad</td>
<td width="14%" align="center" style="font-weight: bold">&nbsp;</td>
<td width="8%" align="center"><strong>Eliminar</strong></td>
</tr><?php
if(isset($_SESSION['carrito'])){
$total=0;
for($i=0;$i<=count($carrito_mio)-1;$i ++){
if($carrito_mio[$i]!=NULL){

?>
<tr bgcolor=>
<td height="18" align="center" valign="middle" nowrap><?php print $carrito_mio[$i]['strNombre']; ?> </td>
<td height="22" align="center" valign="middle"><?php print $carrito_mio[$i]['dblPrecio']; ?></td>
<td height="22" align="right" valign= middle>
<form id="form1" name="form1" method="post" action="">
<label for="cantidad2"></label>
<input name="cantidad2" type="text" id="cantidad2" value="<?php print $carrito_mio[$i]['cantidad']; ?>" size="1" />
<input name="id" type="hidden" id="id" value="<?php print $i; ?>" />
<input name="imageField" type="image" id="imageField" src="img/ACTUALIZ.GIF" alt="actualizar" />
</form></td>
<td height="22" align="right" valign="middle"> <?php print $carrito_mio[$i]['dblPrecio'] * $carrito_mio[$i]['cantidad']; ?> €</td>
<td height="22" align="center" valign="top"><form id="form2" name="form2" method="post" action="">
<input name="id2" type="hidden" id="id2" value="<?php print $i; ?>" />
<input name="imageField2" type="image" id="imageField2" src="img/ico_papelera-2.gif" alt="eliminar" />
</form></td>
</tr>
<?php
$total=$total + ($carrito_mio[$i]['dblPrecio'] * $carrito_mio[$i]['cantidad']);
}
}
}
?>
<tr>

<td height="18">
</td>
<td height="18">&nbsp;</td>
<td height="18" align="right" class="bold">&nbsp;</td>
<td height="18" align="right">&nbsp;</td>
<td height="18" align="center">&nbsp;</td>
</tr>
<tr>
<td height="18" nowrap>&nbsp;</td>
<td height="18">&nbsp;</td>
<td height="18" align="right" class="bold">&nbsp;</td>
<td height="18" align="right">&nbsp;</td>
<td height="18" align="center">&nbsp;</td>
</tr>
<tr>
<td height="18" nowrap>&nbsp;</td>
<td>&nbsp;</td>
<td height="18" align="right" class="bold"><span class="letras_bold"><strong>Total :</strong></span></td>
<td height="18" align="right"><strong><?php print $total; ?> €</strong></td>
<td height="18" align="center">&nbsp;</td>
</tr>
<tr>
<td height="18" colspan="5" align="right" nowrap><form id="form3" name="form3" method="post" action="sumario_sin_iva.php">
<input type="submit" name="button" id="button" value="Comprar" />
</form> </td>
</tr>
</table>

Muchas Gracias por tu interes.
  #6 (permalink)  
Antiguo 03/06/2013, 08:31
 
Fecha de Ingreso: diciembre-2008
Ubicación: Madrid
Mensajes: 6
Antigüedad: 15 años, 4 meses
Puntos: 0
Respuesta: Checkbox

Perdona que te vuelva a molestar, estuve trasteando y consigo que se vea el ultimo libro seleccionado con su precio y todo, pero los demas de la lista no.
Gracias.

Etiquetas: checkbox
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:58.