I am working on one of my assignment for Factorial Program. I am struck on one point.
Fact.php
<html>
<body>
<form action="FactCalc.php" method="post">
Enter a Number: <input type="text" name="number">
<input type="submit" Value="Calculate Factorial">
</form>
</body>
</html>
FactCalc.php
<?php
$num = $_POST["number"];
$factorial = 1;
for ($x=$num; $x>=1; $x--)
{
$factorial = $factorial * $x;
}
echo "Factorial of $num is $factorial";
?>
this program is running fine. I want to return $factorial to Fact.php and display it there below the text box. I am kind of struck here, can you please help.
<?php
if (isset($_POST["number"]))
{
$_POST["number"] = ($_POST["number"] * 1);
include "FactCalc.php";
}
?>
<form action="FactCalc.php" method="post">
<p>
Enter a Number:
<input type="text" name="number">
<input type="submit" Value="Calculate Factorial">
<?php
if (isset($factorial))
{
echo "</p><p>Factorial of $num is $factorial";
}
?>
</p>
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With