Try this:
<?php
if(isset($_POST['submit']))
{
$num=$_POST['T1'];
$fact=1;
while($num>0)
{
$fact=$fact*$num;
$num--;
}
//code for writing result to the textbox.
}
?>
<html>
<title>Factorial</title>
<body>
<form name="f1" method="POST">
number :<input type="text" name="T1" value="<?php isset($num) ? $num : ''?>">
factorial :<input type="text" name="T2" value="<?php isset($fact)? $fact : '';?>">
<input type="submit" name="submit">
</body>
</html>