01/08/2007, 12:00
|
| | Fecha de Ingreso: agosto-2007
Mensajes: 3
Antigüedad: 17 años, 3 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> </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> </p>
</body>
</html>
<?php
$natis->Close();
?>
Última edición por aval; 01/08/2007 a las 13:54 |