Tengo un formulario donde muestro 15 checkbox y algunos otros campos, ahy e colocado un codigo donde solo me deja seleccionar 5 checkbox pero cuando le doy clic en enviar en la BD solo se almacena el valor del primer checkbox seleccionado. Como podria hago para almacenar los datos de los 4 checkbox restante. Bueno ahy muestro los archivos que estoy trabajando.
index.php
Código PHP:
<html>
<head>
<title>Prueba de Pagina</title>
<script type="text/javascript">
function maximoCheckboxarCheckbox(nombre, maximoCheckbox){
for (var i=0; i<nombre.length; i++){
nombre[i].onclick=function(){
var num_chequeados=0;
for (var i=0; i<nombre.length; i++)
num_chequeados+=(nombre[i].checked)? 1 : 0
if (num_chequeados>maximoCheckbox){
alert("Sólo puedes seleccionar " +maximoCheckbox+" canciones");
this.checked=false;
}
}
}
}
</script>
<SCRIPT language="javascript">
<!--
function validar()
{
document.m.submit();
}
//-->
</script>
<script language="javascript">
<!--
function Limpiar()
{
document.m.reset();
}
//-->
</script>
</head>
<body>
<form name="m" method="POST" action="procesa.php">
<table width="8" cellspacing="0" cellpadding="0" border="0">
<tr><td width="8"><input type="checkbox" name="voto" value="1"></td></tr>
<tr><td width="8"><input type="checkbox" name="voto" value="2"></td></tr>
<tr><td width="8"><input type="checkbox" name="voto" value="3"></td></tr>
<tr><td width="8"><input type="checkbox" name="voto" value="4"></td></tr>
<tr><td width="8"><input type="checkbox" name="voto" value="5"></td></tr>
<tr><td width="8"><input type="checkbox" name="voto" value="6"></td></tr>
<tr><td width="8"><input type="checkbox" name="voto" value="7"></td></tr>
<tr><td width="8"><input type="checkbox" name="voto" value="8"></td></tr>
<tr><td width="8"><input type="checkbox" name="voto" value="9"></td></tr>
<tr><td width="8"><input type="checkbox" name="voto" value="10"></td></tr>
<tr><td width="8"><input type="checkbox" name="voto" value="11"></td></tr>
<tr><td width="8"><input type="checkbox" name="voto" value="12"></td></tr>
<tr><td width="8"><input type="checkbox" name="voto" value="13"></td></tr>
<tr><td width="8"><input type="checkbox" name="voto" value="14"></td></tr>
<tr><td width="8"><input type="checkbox" name="voto" value="15"></td></tr>
</table>
<script type="text/javascript">
maximoCheckboxarCheckbox(document.forms.m.voto, 5);
</script>
Nombres : <input type="text" name="nombres" value=""><br>
Apellidos : <input type="text" name="apellidos" value=""><br>
DNI : <input type="text" name="dni" value=""><br>
Email : <input type="text" name="email" value="">
<a href="javascript:validar()" onmouseover="window.status='';return true"><img src="iconos/enviar.jpg" width="70" height="24" border="0"></a>
<a href="javascript:Limpiar()" onmouseover="window.status='';return true"><img src="iconos/cancelar.jpg" width="70" height="24" border="0"></a>
</form>
<body>
</html>
Código PHP:
<html>
<head>
<title>Prueba de Pagina</title>
</head>
<body>
<?php
include("../conexion.php");
$ilimit=0;
$sql="SELECT idusuarios, dni FROM prueba where dni='$dni'";
$iqryvar=mysql_query($sql,$ilink);
while ($row = mysql_fetch_row($iqryvar)) {
$ilimit += 1;
}
mysql_free_result($iqryvar);
if ($ilimit<1)
{
$hostname = gethostbyaddr($REMOTE_ADDR);
// $datum=date("j/n/Y");
$datum = date("Y-m-d");
$insert="insert into prueba (idusuarios, hostname, voto, nombres, apellidos, dni, email, fecha, hora) values('','".$hostname."','".ucwords($voto)."','".$nombres."','".$apellidos."','".$dni."','".$email."','".$datum."','".date("H:i:s")."')";
mysql_query($insert);
$idusr=mysql_insert_id();
$vtit = "Gracias por participar";
echo "<center><font face=arial size=3 color=000000>" .$nombres."Gracias por participar</font></center>";
}
else
{
echo "<script type='text/javascript'>window.alert('Usted ya voto');history.back(-1);</script>";
}
mysql_close($ilink);
?>
<body>
</html>