Wednesday, 18 November 2015

PHP Basics

Dear All,
Congratulations...
Your are here for a good purpose and I promise maximum support....


Let us start PHP basics..

1. Variables and usages. - start.php

<?php



//Display Help in the browser

$hup='Help';
echo $hup;



?>

2. Loops - Factorial of a number - fact.php


<?php

//Display factorial of 9

$n=9;
$f=1;
$i=1;

while($i<=$n)

{
$f=$f*$i;
$i=$i+1;

}

echo "Factorial is ". $f;

?>

3. Factorial of a number using Form input [Need two files 1. Form file 2. Php file]

form.php


<html>
<body>
<form action=findfactorial.php method=post>
<input type=text name=no ><input type=submit vaule='Find Factorial'>
</form>
</body>
</html>
---------------
findfactorial.php


<?php

//Display factorial of 9

$n=$_POST['no'];
$f=1;
$i=1;

while($i<=$n)

{
$f=$f*$i;
$i=$i+1;

}

echo "Factorial is ". $f;

?>









4 comments: