PHP program to find the factorial of a number with form and database
In this tutorial, we will learn about the followings.- Flowchart of PHP program to find the factorial of a number.
- PHP program to find the factorial of a number.
- PHP program to find the factorial of a number with form.
- PHP program to find the factorial of a number with form and database.

1 2 3 4 5 6 7 8 9 10 11 12 13 |
<html> <body> <?php $p = 3; $f = 1; for ($x=$p; $x>=1; $x--) { $f = $f * $x; } echo "Factorial of number is $f"; ?> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<html> <body> <form method="post"> <input type="text" name="name"/> <input type="submit" name="OK" /> </form> <?php if(isset($_POST['OK'])){ $p =$_POST['name']; $f = 1; for ($x=1; $x<=$p; $x++) { $f = $f * $x; } echo "Factorial of number is $f "; } ?> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<html> <body> <form method="post"> <input type="text" name="name"/> <input type="submit" name="OK" /> </form> <?php $con=mysqli_connect("localhost","root","","test"); if(isset($_POST['OK'])){ $p =$_POST['name']; $f = 1; for ($x=1; $x<=$p; $x++) { $f = $f * $x; } echo "Factorial of number is $f "; $sql=mysqli_query($con,"INSERT INTO Factorial (Number,Factorial) VALUES ('$p','$f')"); } ?> </body> </html> |
