Foro de elhacker.net

Programación => PHP => Mensaje iniciado por: alexkof158 en 3 Mayo 2012, 02:48 am



Título: Crear Campos En una celda
Publicado por: alexkof158 en 3 Mayo 2012, 02:48 am
( ! ) Notice: Undefined index: filas in C:\wamp\www\Incertidumbre\tablas.php on line 17
Código:
<body>
<h1>Modelo de Incertidumbre</h1>
<form action="tablas.php" method="POST">
Filas <input type="text" name="filas" size="3" maxlength="20" /><br />
Columnas<input type="text" name="colum" size="3" maxlength="20" /><br />
<input type="submit" value="Enviar" />
</form>
<table>
<?php
$filas = $_REQUEST['filas'];
$colum = $_REQUEST['colum'];
for($i = 0; $i< $filas; $i++){
  echo "
<tr>
";
    for($j=0; $j < $colum; $j++){
      echo "
<td> $i x $j</td>
";
    }
  echo "
</tr>
";
 }
?>
</table>
</body>
:D
Hola, apartir de haber creado la tabla siendo filas X columnas como podria hacer que me imprima un input para ingresar un dato??? :huh:

Gracias de antemano


Título: Re: Notice: Undefined index:
Publicado por: ~ Yoya ~ en 3 Mayo 2012, 02:56 am
Bueno aqui el source con algunas modificaciones para evitar algunos errores...

Código
  1. <body>
  2. <h1>Modelo de Incertidumbre</h1>
  3. <form action="index.php" method="POST">
  4. Filas <input type="text" name="filas" size="3" maxlength="20" /><br />
  5. Columnas<input type="text" name="colum" size="3" maxlength="20" /><br />
  6. <input type="submit" value="Enviar" />
  7. </form>
  8. <table style="border-style: solid;">
  9. <?php
  10.  
  11. //Verifico que se hayan enviado los datos via POST
  12. //Para evitar que todo el codigo corra sin datos que provocarian error...
  13. if(!empty($_POST['filas']) && !empty($_POST['colum'])) {
  14.  
  15. $filas = $_REQUEST['filas'];
  16. $colum = $_REQUEST['colum'];
  17. for($i = 0; $i< $filas; $i++){
  18.  echo "
  19. <tr>
  20. ";
  21.    for($j=0; $j < $colum; $j++){
  22.      echo "
  23. <td style=\"border-style: solid;\"> $i x $j</td>
  24. ";
  25.    }
  26.  echo "
  27. </tr>
  28. ";
  29. }
  30.  
  31. }
  32. ?>
  33. </table>
  34. </body>

Saludos.


Título: Re: Crear Campos En una celda
Publicado por: alexkof158 en 3 Mayo 2012, 03:10 am
Gracias Yoya, ya me estaba leyendo que es mejor utilizar un If o Isset para evitar este tipo de errores, y Gracias