form input - don't se the error

Hello
Please, I try to use inputted number for further code. I am using form input and superglobals but I do nto see the mistake, althought tried using many variations. >:( Can someone help? Many thanks in advance!.



<form id="frm1" action="myform.php" method="post">
	Input number of the rows: <input type="text" value=" " name="m">
	</form>

	

	
<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {
     // collect value of input field
     $a = $_POST['m']; 
}






	$b=2;
echo "<table border='1'><br />";

for ($row = 0; $row < $a; $row ++) {
   echo "<tr>";

   for ($col = 1; $col <= $b; $col ++) {
        echo "<td>", ($col + ($row *$b)), "</td>";
   }

   echo "</tr>";
    }

echo "</table>";

?>

	

E_NOTICE : type 8 – Undefined variable: a – at line 23

[php] if ($_SERVER[“REQUEST_METHOD”] == “POST”) {
// collect value of input field
$a = $_POST[‘m’];
}[/php]

$a only exists if this is true. So, if the method isn’t post, or there is no request, $a doesn’t exist.

if your table should only exist after the form has been submitted, you should include it in the if statement. Otherwise you try populating non-existent data.

Also, line #29, I think you want to use periods, not commas to concatenate the line together…

Here is a nice tutorial on how to handle forms using PHP. Press the “Next Chapter” at the bottom-right
to step thru the pages of the tutorial. It might help you to understand forms a bit better.

http://www.w3schools.com/php/php_form_complete.asp

Good catch, I missed that!

Sponsor our Newsletter | Privacy Policy | Terms of Service