PHP CODES

Develop a Program to print factorial of a number 
 

<html>
     <head>
        <title>Factorial</title>
     </head>
     <body bgcolor ="green" text="yellow">
              <form name="sum" action="fact.php"method="post">
        Enter a Number : <input type="text" name="txt_fact"  />
                         <input type="submit" value="Result" />
       </form>
     </body>
</html>
<?php
        function fact($n)
        {
                $s=1;
                for($i=1; $i<=$n; $i++)
                {
                        $s = $s *$i;
                }       
                echo "the fact is ".$n."= ".$s;
        }
        if(!empty($_POST['txt_fact']))
        {
                fact($_POST['txt_fact']);
        }
?> 
 
Develop a Program to Print multiplication table of given 
number upto 12 
 

<html>
     <head>
        <title>Multiplication Table</title>     
     </head>
        <body bgcolor="pink" text="blue">
        <center>
           <form name="multi" action="multi.php" method="post">
           enter a number :
             <input type="text" name='txt_multi'/>
             <input type="submit" value="submit"/>
            </form>
<?php
   echo "<table border ='1'>";
    if (!empty($_POST['txt_multi']))
    {
      $x=$_POST['txt_multi'];
      for ($i=1;$i<=12;$i++)
        {
          $product =$x*$i;
          echo "<tr>";
          echo "<td width='65'align='center'>".$i."</td>";
          echo "<td width='65'align='center'>*</td>";
          echo "<td width='65'align='center'>".$x."</td>";
          echo "<td width='65'align='center'>".$product."</td>";
          echo "</tr>";
        }
        
     }
     echo "</table>";
?>
        </center>
        </body>
</html> 
 
 
Develop a program to input details in a registration form 
and connect this to sql database

 
 
 
sql query


create database school;

use school;

create table student( regno int ,name varchar(20) , age int , sex varchar (20) , grp varchar (10) );



studentdb.php


<html>

<head>

<title> STUDENT DATABASES</title>

</head>

<body>

<center>

<h1>REGISTRATION FORM</h1>

<form name="student" action="studentdb.php"method="post">

REGNO:<input type="text" name="txt_reg"><br><br>

NAME:<input type="text" name="txt_name"><br><br>

AGE:<input type="text" NAME="txt_age"><br><br>

sex:<input type="text" name="txt_sex"><br><br>

GROUP:<input type="text" NAME="txt_group"><br><br>

<input type="submit" value="SUBMIT">

<input type="reset" value="CANCEL"

<<br><br>

</form>

<?php

mysql_connect("localhost","root");

mysql_select_db("school");

if(isset($_POST['txt_reg']))

{

$regno=$_POST['txt_reg'];

$name=$_POST['txt_name'];

$age=$_POST['txt_age'];

$sex=$_POST['txt_sex'];

$group=$_POST["txt_group"];

$sql_ins="insert into student values(".$regno.",'".$name."',".$age.",'". $sex."','".$group."')";

mysql_query($sql_ins);

$sql_sel="select * from student";


$result_set=mysql_query($sql_sel);

?>

<table border='1'>

<tr>

<th>REGNO</th>

<th>NAME</th>

<th>AGE</th>

<th>SEX</th>

<th>GROUP</th>

</tr>

<?php


while($record=mysql_fetch_array($result_set))

{

echo"</tr>";

echo"<td width='70' align='center'>".$record['regno']."</td>";

echo"<td width='70'>".$record['name']."</td>";

echo"<td width='70' align='center'>".$record['age']."</td>";

echo"<td width='70'>".$record['sex']."</td>";

echo"<td width='70'>".$record['grp']."</td>";

echo"</tr>";

}

}

?>

</table>

</center>

</body>

</html>

 

Comments