Foros del Web » Programando para Internet » PHP »

como insertar check box a la bd con php

Estas en el tema de como insertar check box a la bd con php en el foro de PHP en Foros del Web. Saludos, alguien me podria orientar de como inserto unos check box en mysql, tengo mi codigo asi: Código: <INPUT TYPE="CHECKBOX" NAME="reque[0]" VALUE="Laptop" onfocus="Intermitencia()" onBlur="pararTimer()" CHECKED ...
  #1 (permalink)  
Antiguo 06/06/2007, 16:03
Avatar de ferbux  
Fecha de Ingreso: mayo-2007
Ubicación: por ahí intentado ayudar
Mensajes: 823
Antigüedad: 16 años, 11 meses
Puntos: 6
Pregunta como insertar check box a la bd con php

Saludos, alguien me podria orientar de como inserto unos check box en mysql, tengo mi codigo asi:

Código:
<INPUT TYPE="CHECKBOX" NAME="reque[0]" VALUE="Laptop" onfocus="Intermitencia()" onBlur="pararTimer()" CHECKED > Laptop <BR> 
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE="CHECKBOX" NAME="reque[1]" VALUE="conexion" > Conexi&oacute;n a red (INTRANET)<BR> 
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE="CHECKBOX" NAME="reque[2]" VALUE="inter" > Salida a INTERNET<BR> 
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE="CHECKBOX" NAME="reque[3]" VALUE="Ca&ntilde;&oacute;n;" > Ca&ntilde;&oacute;n <BR> 
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE="CHECKBOX" NAME="reque[4]" VALUE="Servicio de cafeter&iacute;a" > Servicio de cafeter&iacute;a

y en el php hago la insercion asi:

Código:
$ins = "INSERT INTO salax (id_sala, id_emp, fecha_soli, motivo, reque, tot_per, de, a) 
			VALUES ('$pryestatus','$emp','$fecha','$moti','$reque','$per','$de','$a')";
lo intento meter como una arreglo pero no inserta $reque slo inserta todos los demás.

Si alguien me puede orientar se lo agradezco.
  #2 (permalink)  
Antiguo 06/06/2007, 22:45
Avatar de minkweb  
Fecha de Ingreso: septiembre-2005
Mensajes: 443
Antigüedad: 18 años, 7 meses
Puntos: 14
Re: como insertar check box a la bd con php

mmm la verdad no se que quieres hacer. si quieres que $reque tenga diversos valores o si es 1 solo valor

si es varios valores t recomiendo q con php tomes todos los seleccionados y los metas en 1 sola variable..

si es un solo valor entoncs no tienes x q colocarle reque"->[0]<-" eso

cualquier cosa explicarte mejor
  #3 (permalink)  
Antiguo 01/08/2007, 12:00
 
Fecha de Ingreso: agosto-2007
Mensajes: 3
Antigüedad: 16 años, 8 meses
Puntos: 0
Re: como insertar check box a la bd con php

hola.. tengo un problema al insertar los valores de los checkbox a una tabla... aqui anexo mi codigo, espero puedan ayudarme gracias.


<script type="text/JavaScript">
<!--
function validar(form1) {
var total = 0;
//var natisv: String[] = new String[max];
//var j=0;
var max = form1.TOTAL.value;
//var max = form1.NATI.length; //cuanta el numero de check


if(form1.DESCRIPTION.value == '')
{
alert("PLEASE INSERT CODE OF DESCRIPTION, IS EMPTY");
//alert("numero de checkbok" + max);
form1.DESCRIPTION.focus();
return(false);
}

for (var idx = 0; idx < max; idx++) { //ciclo que recorre y valida cada check si fue seleccionado
if (form1.NATI[idx].checked == true) {
total += 1;
}
}
//alert("Has seleccionado un total de " + total + " casillas.");
if(total<=0)
{
alert("SELECT ONE O MORE NATIS PLEASE...");
form1.NATI[1].focus();
return(false);
}

}
//-->
</script>

<?php
//Connection statement
require_once('Connections/BD.php');
//Aditional Functions
require_once('includes/functions.inc.php');
include("no_cache.php");
// begin Recordset
$query_natis = "SELECT distinct(NATI) FROM nati_2";
$natis = $BD->SelectLimit($query_natis) or die($BD->ErrorMsg());
$totalRows_natis = $natis->RecordCount();
// end Recordset

// build the form action
$ejecuto =1;
$insertGoTo = 1;
$selection = $_POST['NATIH'];

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
{
$aLista=array_keys($_POST['NATI']);
foreach($aLista as $iId) {
$insertSQL = sprintf("INSERT INTO cards (id, description, nati) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['DESCRIPTION'], "text"),
GetSQLValueString($_POST['NATI'.$aLista], "text"));
$Result2 = $BD->Execute($insertSQL) or die($BD->ErrorMsg());
}
/* $valor = "NATI";
for($r=1; $r<=$totalRows_natis; $r++)
{
if($r<10){$valor = "NATI0";}else if($r>=10){$valor="NATI";}
$valores = $valor.$r;
if (isset($_POST[$valores])){
$insertSQL = sprintf("INSERT INTO cards (id, description, nati) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['DESCRIPTION'], "text"),
GetSQLValueString($valores, "text"));
$Result2 = $BD->Execute($insertSQL) or die($BD->ErrorMsg()); */
$insertGoTo = 0;

}

/*<!-- for($i=0; $i<=$totalRows_natis; $i++)
{
$temp = $i;
if($i<10){
$cam = '0'.$i;
$i = $cam;
}-->*/
// $namenati = $_POST['NATI0'.$i+1];}
//$namenati = $_POST['NATI'.$i+1];}

/* $insertSQL = sprintf("INSERT INTO cards (id, description, nati) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['DESCRIPTION'], "text"),
GetSQLValueString($_POST['NATI'.$i], "text"));
$Result2 = $BD->Execute($insertSQL) or die($BD->ErrorMsg());
$insertGoTo = 0;
$i = $temp;
*/ //}
//}
if (isset($_SERVER['QUERY_STRING'])) {
if($insertGoTo==0)
{
echo "<script>";
echo "alert('Congratulations your added succefully!!!')";
echo "</script>";
}
}


?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php //PHP ADODB document - made with PHAkt 3.7.1?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>ADD_CARD.PHP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style16 {color: #FFFFFF}
.style32 {color: #FFFFFF;
font-size: x-small;
font-weight: bold;
}
a:link {
color: #000000;
}
a:visited {
color: #000000;
}
.style33 {color: #009933}
-->
</style>
</head>

<body>
<table width="100%" height="32" border="0" align="center">
<tr>
<td height="28" bgcolor="#009933"><div align="center" class="style16 style4"><strong>ADD CARD </strong></div></td>
</tr>
</table>

<form method="post" id="form1" name="form1" action="ADD_CARD.PHP" onSubmit="return validar(this)">
<table width="42%" border="0" align="center">
<tr>
<td height="20" colspan="2"><div align="center"><a href="javascript:close()"><strong>CLOSE WINDOW </strong></a></div></td>
</tr>
<tr>
<td height="21"><div align="right"><strong>DESCRIPTION:</strong></div></td>
<td><input name="DESCRIPTION" type="text" id="DESCRIPTION" value="" size="32" /></td>
</tr>
</table>
<table width="304" align="center">
<tr valign="baseline">
<td width="296" height="38" align="right" nowrap><div align="center" class="style33"><strong><u>SELECT THE NATI's TO CARD </u></strong></div></td>
</tr>
<tr valign="baseline">
<?php $i=0; do{ ?>
<td align="right" nowrap>
<div align="center">
<?php if($i<10){?> <strong>NATI0<?php echo $i+1;}else if($i>=10){?><strong>NATI<?php echo $i+1;}?></strong>
<input type="checkbox" name="NATI" value="<?php if($i<10){ echo "NATI".$i+1;} else if ($i>10) {echo "NATI".$i+1;}?>">
</div></td>
<?php $i++; $mod=$i%7;
if($mod==0)
{ ?></tr>
<?php }
}while($i<=$totalRows_natis);?>

<tr valign="baseline">
<td align="right" nowrap>

<div align="center">
<input name="submit" type="submit" value="ADD CARD" />
</div></td>
</tr>
</table>
<p>&nbsp; </p>
<p>
<input name="id" type="hidden" id="id">
<input type="hidden" name="MM_insert" value="form1" />
<input name="TOTAL" type="hidden" id="TOTAL" value="<?php echo $totalRows_natis;?>">
</p>
</form>
<table width="100%" height="19" border="0" align="center">
<tr>

</tr>
</table>
<p>&nbsp;</p>
</body>
</html>
<?php
$natis->Close();
?>

Última edición por aval; 01/08/2007 a las 13:54
  #4 (permalink)  
Antiguo 01/08/2007, 13:52
 
Fecha de Ingreso: agosto-2007
Mensajes: 3
Antigüedad: 16 años, 8 meses
Puntos: 0
Re: como insertar check box a la bd con php

Hola ya solucione mi error.. aqui les anexo la parte que modifique por si alguien comete los mismos errores que yo jijiji..

//Esto es en la parte de PHP aqui realice cambios


$insertGoTo = 1;
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
{
for($aLista=1; $aLista<=$totalRows_natis+1; $aLista++) {
if(isset($_POST['NATI0'.$aLista]))
{
$insertSQL1 = sprintf("INSERT INTO cards (id, description, nati) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['DESCRIPTION'], "text"),
GetSQLValueString($_POST['NATI0'.$aLista], "text"));
$Result1= $BD->Execute($insertSQL1) or die($BD->ErrorMsg());
$insertGoTo = 0;
}
if(isset($_POST['NATI'.$aLista]))
{
$insertSQL2 = sprintf("INSERT INTO cards (id, description, nati) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['DESCRIPTION'], "text"),
GetSQLValueString($_POST['NATI'.$aLista], "text"));
$Result2 = $BD->Execute($insertSQL2) or die($BD->ErrorMsg());
$insertGoTo = 0;
}
}
}
if (isset($_SERVER['QUERY_STRING'])) {
if($insertGoTo==0)
{
echo "<script>";
echo "alert('Congratulations your added succefully!!!')";
echo "</script>";
}
}



//acontinuacion en la parte de html


<table width="304" align="center">
<tr valign="baseline">
<td width="296" height="38" align="right" nowrap><div align="center" class="style33"><strong><u>SELECT THE NATI's TO CARD </u></strong></div></td>
</tr>
<tr valign="baseline">
<?php $i=1; do{ ?>
<td align="right" nowrap>
<div align="center">
<?php if($i<10){?> <strong>NATI0<?php echo $i;}else if($i>=10){?><strong>NATI<?php echo $i;}?></strong>
<input type="checkbox" name="<?php if($i<10){echo "NATI0".($i);} else if($i>=10){echo "NATI".($i);}?>" value="<?php if ($i<10){echo "NATI0".($i);}else if($i>=10){echo "NATI".($i);}// si ven este detalle de los aprentesis, pues eso era... y otras cositas del inserte... espero les sirva a alguien
?>">
</div></td>
<?php $i++; $mod=$i%7;
if($mod==0)
{ ?></tr>
<?php }
}while($i<=$totalRows_natis+1);?>

<tr valign="baseline">
<td align="right" nowrap>

<div align="center">
<input name="submit" type="submit" value="ADD CARD" />
</div></td>
</tr>
</table>

Saludos...
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 20:07.