Foros del Web » Programando para Internet » PHP »

pasar array a php error

Estas en el tema de pasar array a php error en el foro de PHP en Foros del Web. Buenas Tengo este codigo Código HTML: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código HTML: Ver original <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   ...
  #1 (permalink)  
Antiguo 05/11/2012, 10:40
 
Fecha de Ingreso: octubre-2012
Mensajes: 12
Antigüedad: 11 años, 5 meses
Puntos: 0
pasar array a php error

Buenas

Tengo este codigo
Código HTML:

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3.         <html xmlns="http://www.w3.org/1999/xhtml">
  4.         <head>
  5.         <title>Contar checkboxes marcados</title>
  6.         <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  7.         <script type="text/javascript">
  8.         //<![CDATA[
  9.       function limitar(grupo,limite){
  10.       var grupo=document.getElementsByName(grupo);
  11.       var limite=limite
  12.       for (var i=0; i < grupo.length; i++){
  13.        grupo[i].onchange=function(){
  14.        var tildados=0
  15.        for (var i=0; i < grupo.length; i++)
  16.         tildados+=(grupo[i].checked)? 1 : 0
  17.        if (tildados > limite){
  18.           alert("solo se permiten "+limite+" selecciones")
  19.           this.checked=false
  20.           }
  21.          }
  22.         }
  23.        }
  24.        
  25.        //]]>
  26.         </script>
  27.         </head>
  28.         <body>
  29.         <form action="#">
  30.         <p>
  31.         <input type="checkbox" name="PREGUNTA9[]" onchange="limitar(this.name,3);" /> a<br />
  32.         <input type="checkbox" name="PREGUNTA9[]" onchange="limitar(this.name,3);" /> b<br />
  33.         <input type="checkbox" name="PREGUNTA9[]" onchange="limitar(this.name,3);" /> c<br />
  34.         <input type="checkbox" name="PREGUNTA9[]" onchange="limitar(this.name,3);" /> d<br />
  35.         <input type="checkbox" name="PREGUNTA9[]" onchange="limitar(this.name,3);" /> e<br />
  36.         </p>
  37.          
  38.         <p>
  39.         <input type="checkbox" name="PREGUNTA10[]" onchange="limitar(this.name,2);" /> f<br />
  40.         <input type="checkbox" name="PREGUNTA10[]" onchange="limitar(this.name,2);" /> g<br />
  41.         <input type="checkbox" name="PREGUNTA10[]" onchange="limitar(this.name,2);" /> h<br />
  42.         <input type="checkbox" name="PREGUNTA10[]" onchange="limitar(this.name,2);" /> i<br />
  43.         <input type="checkbox" name="PREGUNTA10[]" onchange="limitar(this.name,2);" /> j<br />
  44.         </p>
  45.          
  46.         </form>
  47.         </body>
  48.         </html>



Y funciona correctamente pero el problema viene cuando lo intento pasar a la base de datos.
¿Cual es el problema? Que si clickeo 3 checkbox y pulso en enviar da igual cual de ellos pulse que a la base de datos me enviara los 3 primeros como correctos(pasandome el valor que le defini) y los demas en 0.

este es el codigo php

Código PHP:
Código PHP:
Ver original
  1. $pregunta9= $_REQUEST['PREGUNTA9'];
  2. $pregunta91 = $pregunta9[0];
  3. $pregunta92 = $pregunta9[1];
  4. $pregunta93 = $pregunta9[2];
  5. $pregunta94 = $pregunta9[3];
  6. $pregunta95 = $pregunta9[4];

Una vez mas gracias.
  #2 (permalink)  
Antiguo 05/11/2012, 11:11
 
Fecha de Ingreso: abril-2009
Ubicación: en un lugar de la mancha
Mensajes: 236
Antigüedad: 15 años
Puntos: 38
Respuesta: pasar array a php error

es mas seguro pasar el formulario a traves de un metodo post o get y depsues recogerlo con ese metodo y no con REQUEST por lo ke:

1- te falta el metodo por el cual kieres pasar el formulario
2- te falta el nombre en el action donde kieres pasar el formulario
3- te falta el boton de enviar en el formulario
4- te falta el valor de cada chekbox.


despues de estos primero 4 detalles seguir chequeando ke error te da tu script

Código PHP:
<form action="TU_PAGINA.PHP" method="post">
        <p>
        <input type="checkbox" name="PREGUNTA9[]" onchange="limitar(this.name,3);" value="a" /> a<br />
        <input type="checkbox" name="PREGUNTA9[]" onchange="limitar(this.name,3);" value="b" /> b<br />
        <input type="checkbox" name="PREGUNTA9[]" onchange="limitar(this.name,3);" value="c" /> c<br />
        <input type="checkbox" name="PREGUNTA9[]" onchange="limitar(this.name,3);" value="d" /> d<br />
        <input type="checkbox" name="PREGUNTA9[]" onchange="limitar(this.name,3);" value="e" /> e<br />
        </p>
         
       
    <input type="submit" value="Enviar"> 
</form>
</body>
</html>
        
<?php
        
if(isset($_POST['PREGUNTA9'])){
            
            
$preg  $_POST['PREGUNTA9'];
            
            
$val = array();
            
            foreach(
$preg as $p)
                       {
                
$val[] = $p;
               }
            
               
print_r($val);
            
        }
        
?>
buena suerte

Última edición por rolygc; 05/11/2012 a las 11:23

Etiquetas: html
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 05:23.