Sunday 15 May 2011

html - PHP 'loop for' with input text form -



html - PHP 'loop for' with input text form -

i'm doing programme have insert number ("x"), , generate "x" number of "input forms" come in diferent numbers later, calculate operations.

i have generate forms using for, , then, pass results submit button $_post next page. then, when seek results for, doesn't works , problems.

notice: undefined variable: num4 in...

what doing wrong?

thank you!

<?php /*here number create "x" number of forms*/ if (isset($_post["num"])) { $num=$_post["num"]; $_post["num"]=$num; if ( is_numeric($num) , $num>=0) { echo"<form action=\"tercera.php\" method=\"post\">"; echo "quina operaciĆ³ vols fer?:<br><br> " . "<input type=\"radio\" name=\"operacio\" value=\"suma\"/>suma " . "<input type=\"radio\" name=\"operacio\" value=\"mitja\"/>mitja" . "<input type=\"radio\" name=\"operacio\" value=\"major\"/>major" . "<input type=\"radio\" name=\"operacio\" value=\"menor\"/>menor</p>"; /*here create loop generate forms "numero[$i]" */ ($i=1; $i<=$num; $i++) { echo" <input type=\'text\' name=\'numero[$i]\' maxlength=\'10\' size=\"10\"/>"; } echo "<p><input type='submit' value='calcula' /></p>"; } else { echo "<h3>has d'escriure united nations numero mes gran que 0, torna-ho intentar."; } }//isset*/ ?> /*/ next php page /*/ <?php if (isset($_post["operacio"])) $operacio=$_post["operacio"]; //here numbers of lastly page ($i=1; $i<=2; $i++) { if (isset($_post["numero[$i]"])) $num2=$_post["numero[$i]"] ; //here error: undefined variable: num2 echo $num2; } //this part ok ... if ($operacio == "suma") { echo "i equals 0"; } elseif ($operacio == "mitja") { echo "i equals 1"; } elseif ($operacio == "major") { echo "i equals 2"; } elseif ($operacio == "menor") { echo "i equals 3"; } if ( is_numeric($num) , $num>=0) { ($i=1; $i<=$num; $i++) { } } else { echo "<h3>has d'escriure united nations numero mes gran que 0, torna-ho intentar."; } //isset*/ ?>

in sec page don't utilize this:

if (isset($_post["numero[$i]"])) $num2=$_post["numero[$i]"];

because field doesn't exist. when utilize array of fields, need field, , after position, instance, work:

if(isset($_post["numero"]) && isset($_post["numero"][$i])) $num2=$_post["numero"][$i];

remember, using field array.

if don't want in troubles elements in array, utilize (after knowing $_post["numero] exists):

foreach($_post["numero"] $num) { echo $num; // or waht want do. }

i hope help you.

php html forms

No comments:

Post a Comment