FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Getting the info from a "form" thats in a for cicl





Nachui
There's my code
index.php
Code:
<html>
    <head>
   <title></title>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
   <form action="numeros.php">
Cuántos números vas a ingresar?
         <input type="text" name="cantidad"/>
    <input type="submit" value="Ir !"/>
        </form>
    </body>
</html>

numeros.php
Code:
<?php
session_start();
$cantidad = $_REQUEST['cantidad'];
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
   Por favor ingresa tus numeros para calcular su mínimo,
   máximo, rango y promedio.
   <?php
   if (empty($cantidad)||!is_numeric($cantidad)){
   echo 'Por favor ingresa un valor válido para la cantidad de números<br>';
   echo "<form action='index.php' >";
   echo "<input type='submit' value='Volver'/>";
   echo "</form>";      
   } else{
       echo "<form action='calculos.php'>";
   $_SESSION['numeros'] = array();
   for($i=1;$i<=$cantidad;$i++){
       echo "$i : <input type='text' name='numero'.$i/><br>";
   }
       echo "<p><input type='submit' value='Calcular'/></p>";
       echo "</form>";
   }
   $_SESSION['cantidad']=$cantidad;
   ?>
      
   </body>
</html>

calculos.php
Code:
<?php
session_start();
$cantidad=$_SESSION['cantidad'];
$numerosescritos = " ";
   for($i=1;$i<=$cantidad;$i++){
        $numeros[$i] = $_REQUEST[('numero'.$i)];
        $numerosescritos .= $numeros[$i];
   }
   echo "$numerosescritos";

?>
<html>
    <head>
   <title></title>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
   <?php
   echo "$numerosescritos";
   ?>
    </body>
</html>


The idea in this webpage is that you select al ammount of number to enter (index.php), then enter them (numeros.php) and then the page has to calculate the range, min and max number and the average (calculos.php, but i havent made that part yet).
i'm getting this error:
Notice: Undefined index: numero1 in C:\xampp\htdocs\funciones\calculos.php on line 6

Notice: Undefined index: numero2 in C:\xampp\htdocs\funciones\calculos.php on line 6

Notice: Undefined index: numero3 in C:\xampp\htdocs\funciones\calculos.php on line 6
.
.
.
i know what i means, but i've been trying to fix it and i can't Sad !
my idea was to make a "sentence"($numerosescritos) with all the numbers entered, then use explode and have them back... or maybe make an array of the numbers, but i need to fix this before i can do anything...
jmraker
The notices are warnings that those keys do not exist in the array. When they don't exist it should act like the array item had an empty string for a value.

I'm guessing if you view the page source you'd find invalid html
Code:
1 : <input type='text' name='numero'.1/><br>
2 : <input type='text' name='numero'.2/><br>

because of the quote ending the name attribute before the dot and number

Some things I would fix would be in the form, specify the numbers as an array
Code:
for($i = 1;$i <= $cantidad;$i++){
       echo $i . ' : <input type="text" name="numero['.$i . ']" /><br>';
}

and in the calculation program you can use
Code:
foreach($_REQUEST['numero'] as $i=>$v){
      $numeros[$i] = (int)$v;  // convert string to an integer, use (float) to convert to a floating point number
      $numerosescritos .= $numeros[$i];
}


$numerosescritos will end up as a concatenation of all the numbers together without spaces " 1223" if they entered "1", "22", and "3"
If you want commas in between the numbers you could use $numerosescritos = implode(", ", $numeros);
If you want $numerosescritos as a total you'd initialize it with a zero instead of a space and use the += operator instead of the .=


You can hide the warning messages with the error_reporting function
http://us.php.net/manual/en/function.error-reporting.php
Related topics
Okay, I'm done trying to use CSS for layout.
Email Encryption - Do you / would you use it?
US Government Take Google To Court
TV Addiction: It's not our fault shows have gotten better ;]
python script???
I need help getting a domain name! without a credit card!
Check OUT MINE
help
Flat file question
Show your films
Basilisk?
Religion: The Root of All Evil?
Should younger teenagers be able to drive drunk people home?
Why are .info domains cheaper than .com or .net domains?
PLEASE HELP :(
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.