Program to show a table of a number till 10
In this tutorial, we will learn that how to print the table of a number and number will be input by the user. For this purpose, we need to make two text boxes in a form and then assign names to each of the form element. For example, here we assign the following names.- Input type text is named as “value”.
- Input type submit is names as “btn“.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<form Method="post"> <br><br> Enter number:<input type="text" name="value"/><br><br> <input type="submit" name="btn" value="print table" /> </form> <?php if(isset($_POST['btn'])) { $n=$_POST['value']; $res=0; for($i=1;$i<=10;$i++) { $res=$n*$i; echo $n; echo"*"; echo $i; echo "="; echo $res; echo "<br>"; } } ?> |

Line No | Code | Explanation |
8 | if(isset($_POST[‘btn’])) | It will check that values are successfuly POSTED from form or not. |
10 | $n=$_POST[‘value’]; | Right side takes the values from the form element (named as “value”) and this value is the value which is posted by user with the help of form. Now we can put the value of right side into left side into the variable $n. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<form Method="post"> <br><br> Enter number:<input type="text" name="value"/><br><br> <input type="submit" name="btn" value="print table" /> </form> <?php if(isset($_POST['btn'])) { $n=$_POST['value']; $res=0; for($i=1;$i<=20;$i++) { $res=$n*$i; echo $n; echo"*"; echo $i; echo "="; echo $res; echo "<br>"; } } ?> |