Write a PHP program to implement Create, Read, Update and Display operations on Teacher table with attributes(tid, tname, address, subject). (Use Radio Buttons)

Teacher.php
<HTML>
<BODY>
<FORM method=POST action="<?php echo $_SERVER['PHP_SELF'] ?>">
<b><h3>Perform operations on the TEACHER Table</b><BR>
<INPUT type=radio name="choice" value="1">Create<BR>
<INPUT type=radio name="choice" value="2">Insert<BR>
<INPUT type=radio name="choice" value="3">Update<BR>
<INPUT type=radio name="choice" value="4">Delete<BR>
<INPUT type=submit name=submit value="Operation Perform"><BR>
</FORM>
<?php
$hn="localhost";
$db="Teach";
$un="root";
$psw="";
$link=mysqli_connect($hn,$un,$psw,$db);
if(isset($_POST['submit']))
{
    $ch=$_POST['choice'];
            if($ch=='1')
    {
                        if(!$link)
                        {
                                    die('connection faild:'.mysql_error());
                        }
                                                $sql="create table teacher(tid int,tname varchar(10),addr varchar(20),sub varchar(10))";
                        if(mysqli_query($link,$sql))
                        {
                                                echo"Table created Successfully";
                        }
                        else
                        {
                                    echo"Unable to perform";
                        }
            }
    if($ch=='2')
    {
                        if(!$link)
                        {
                                    die('connection faild:'.mysql_error());
                        }
                                               
                                    $sql="insert into teacher values('102','Prof.Bhilare','Malegaon','PHP')";
                        if(mysqli_query($link,$sql))
                        {
                                    echo"Row inserted Successfully";
                        }
                        else
                        {
                                    echo"Unable to perform";
                        }
            }
            if($ch=='3')
            {
                        if(!$link)
                        {
                                    die('connection faild:'.mysql_error());
                        }
                                               
                                    $sql="update teacher SET addr='Baramati' where tid='101'";
                        if(mysqli_query($link,$sql))
                        {
                                    echo"Record Updated Successfully";
                        }
                        else
                        {
                                    echo"Unable to perform";
                        }
            }
    if($ch=='4')
    {
                        if(!$link)
                        {
                                    die('connection faild:'.mysql_error());
                        }
                                    $sql="delete from teacher where tid='101'";
                        if(mysqli_query($link,$sql))
                        {
                                    echo"Record Deleted Successfully";
                        }
                        else
                        {
                                    echo"Unable to perform";
                        }
    }
}
mysqli_close($link);
?>
</BODY>

</HTML>






Considerer the following entities and their relationships Student (Stud_id,name,class) Competition (c_no,c_name,type) Relationship between student and competition is many-many with attribute rank and year. Create a RDB in 3NF for the above and solve the following. Using above database write a script in PHP to accept a competition name from user and display information of student who has secured 1st rank in that competition

StudCom.html
<html>
<body>
<form method="get" action="studcomp.php">
<fieldset>
            <legend>Enter Competition Name :</legend><br>
<input type="text" name="cnm"><br><br>
</fieldset>
<div align="center">
<input type="submit" value="Show Result">
</div>
</form>
</body>
</html>
StudCom.php
<?php
        $cnames=$_GET['cnm'];
                       
                        $hn="localhost";
                        $un="root";
                        $pass="";
                        $db="students";
                       
                        $link=mysqli_connect($hn,$un,$pass,$db);
            if(!$link)
            {
                        die('Connection Failed:'.mysqli_error());
            }
            //$sql="SELECT * FROM student WHERE CNo IN (SELECT CNo FROM competition WHERE CName = '".$cname."')";
            $sql="select * from student,competition,studcomp where student.Sid=studcomp.Sid and competition.CNo=studcomp.CNo and rank='1' and CName='".$cnames."'";
            $res=mysqli_query($link,$sql);          
                       
            if(mysqli_num_rows($res)>0)
            {
                        while($row=mysqli_fetch_assoc($res))
         {
                                    echo"Stud No : ".$row['Sid']."<br>"."  Name  : ".$row['SName']."<br>";
                                    echo"Class :  ".$row['SClass']."<br>";
                                    echo"--------------------------"."<br>";
                        }
            }
            else
            {
                        echo"error";
            }
            mysqli_close($link);

?>





Write a PHP Script to Upload the file and display its information.(use $_FILES).

UploadFile.html

<html>
<body>
<form method=post action="Uploadfile.php" enctype="multipart/form-data">
File Name : <input type="file" name="file" id="file" size=40%><br>
<input type=submit name=submit value=Upload File>
</form>
</body>
</html>

UploadFile.php

<?php
if($_FILES["file"]["error"]>0)
{
            echo"Error : ".$_FILES["file"]["error"]."<br>";
}
else
{
            echo"Upload File : ".$_FILES["file"]["name"]."<br>";
            echo"Type : ".$_FILES["file"]["type"]."<br>";
            echo"Size : ".($_FILES["file"]["size"]/1024)." kb<br>";
            echo"Temporary Storage : ".$_FILES["file"]["tmp_name"];
}

?>




Create a form to accept employee details like name, address and mobile number. Once the employee information is accepted, then accept LIC information like policy_no, name, premium. Display employee details and LIC details on next form.(use COOKIE)

Emp.html

<html>
<body>
<form method="POST" action="Lic.php">
Enter EMP No : <input type=text name="eno"><br>
Enter EMP Name : <input type=text name="name"><br>
Enter Address : <input type=text name="addr"><br>
<input type=submit value=Submit>
</form>
</body>
</html>


LIC.php
<?php
session_start();
$_SESSION['eno']=$_POST['eno'];
$_SESSION['name']=$_POST['name'];
$_SESSION['addr']=$_POST['addr'];
echo"Hello ".$_SESSION['name']." enter LIC details<br>";
?>
<form method="POST" action="Display.php">
Plan No:<input type="text" name="pno"><br>
Plan Name :<input type="text" name="pname"><br>
Premium :<input type="text" name="pre"><br>
<input type=submit value=Display>
</form>
Display.php

<?php
    session_start();
            echo"<Center>"."<b>Employee Details</b>"."<br>";
            echo"Emp No:".$_SESSION['eno']."<br>";
            echo"Emp name:".$_SESSION['name']."<br>";
            echo"Address:".$_SESSION['addr']."<br>"."<hr>";
            echo"<b>LIC Plan Details:</b>"."<br>";
            echo"Plan No:".$_REQUEST['pno']."<br>";
            echo"Plan Name:".$_REQUEST['pname']."<br>";
            echo"Premium:".$_REQUEST['pre']."<br>"."<hr>";

 ?>





Write a script to keep track of number of times the web page has been accessed (use $_COOKIE)

<html>
<body>
<SCRIPT>
function GetCookie (name)
{
            var arg = name + "=";
            var alen = arg.length;
            var clen = document.cookie.length;
            var i = 0;
            while (i < clen)
            {
                        var j = i + alen;
                        if (document.cookie.substring(i, j) == arg)
                        return getCookieVal (j);
                        i = document.cookie.indexOf(" ", i) + 1;
                        if (i == 0) break;
            }
            return null;
}
function SetCookie (name, value)
{
            var argv = SetCookie.arguments;
            var argc = SetCookie.arguments.length;
            var expires = (argc > 2) ? argv[2] : null;
            var path = (argc > 3) ? argv[3] : null;
            var domain = (argc > 4) ? argv[4] : null;
            var secure = (argc > 5) ? argv[5] : false;
            document.cookie = name + "=" + escape (value) +
            ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
            ((path == null) ? "" : ("; path=" + path)) +
            ((domain == null) ? "" : ("; domain=" + domain)) +
            ((secure == true) ? "; secure" : "");
}
function DeleteCookie (name)
{
            var exp = new Date();
            exp.setTime (exp.getTime() - 1);
            var cval = GetCookie (name);
            document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt()
{
            var count = GetCookie('count')
            if(count == null)
            {
                        SetCookie('count','1')
                        return 1
            }
            else
            {
                        var newcount = parseInt(count) + 1;
                        DeleteCookie('count')
                        SetCookie('count',newcount,exp)
                        return count
            }
}
function getCookieVal(offset)
{
            var endstr = document.cookie.indexOf (";", offset);
            if (endstr == -1)
            endstr = document.cookie.length;
            return unescape(document.cookie.substring(offset, endstr));
}
</SCRIPT>
<SCRIPT>
            document.write("You've been here <b>" + amt() + "</b> times accessed webpage.")
</SCRIPT>
</body>

</html>



Create a login form with a username and password. Once the user logs in, the second form should be displayed to accept user details (name, city, phoneno). If the user doesn’t enter information within a specified time limit, expire his session and give a warning otherwise Display Details($_SESSION).

Login.html
<html>
<form method="POST" action="login.php" >
<p>User Name: <input type="text" name="user"><br>
<p>Password :<input type="password"><br><br>
<input type="submit" value="Login"><br>
</form>
</html>
Login.php
<?php
$auth_yes=0;
session_start();
session_register();
#tm=time();
?>

<form method="GET" action="new.php">
<fieldset>
<legend>Enter username and password</legend>

<p>Roll_No:&nbsp&nbsp&nbsp<input type="text" name="rno"><br>
<p>Name:&nbsp&nbsp&nbsp<input type="text" name="nm"><br>
<p>City:&nbsp&nbsp&nbsp:&nbsp&nbsp&nbsp<input type="text" name="ct"><br><br>
<input type="submit" value=Submit>
</form>
New.php
<?php
$a=$_GET['rno'];
$b=$_GET['nm'];
$c=$_GET['ct'];
session_start();
$newt = $tm+60;
if($newt > time())
echo"time out";
else
{
echo"Roll_No=$a"."<br>";
echo"Name=$b"."<br>";
echo"City=$c"."<br>";
}
session_destroy();

?>