Search This Blog

Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Thursday, 16 February 2023

B13.(New) PHP Program to read data from MySQL table and calculate attendance percentage & Attendance Shortage.

 <!-- 13. PHP Program to read data from MySQL table and calculate attendance percentage & Attendance Shortage. -->

<!-- Run this query from MySQL [insert into prog13 values('BC180123','XYZ','WP',40,36,0);]-->

<html>

<head>

<title>Read data and update mysql table using php </title>

</head>

<body bgcolor=gray text=yellow>

<?php

// Establish Connection with Server

$connection = mysql_connect("localhost", "root", "");

// Selecting Database

$db = mysql_select_db("test", $connection);

//MySQL Query to read data

$query = mysql_query("select * from prog13", $connection);

echo "<h3>Student Attendance Details</h3>";

echo "<table border=3 cellspacing=5>";

echo"<tr><th>RegNo</th><th>StudentName</th><th>Subject</th><th>ClassesHeld</th><th>ClassesAttended</th><th>AttendancePercentage</th><th>AttendanceShortage</th></tr>";

while ($row = mysql_fetch_array($query))

{

    echo "<tr><td>".$row['RegNo']."</td>";

    echo "<td>".$row['StudentName']."</td>";

    echo "<td>".$row['Subject']."</td>";

    echo "<td>".$row['ClassesHeld']."</td>";

    echo "<td>".$row['ClassesAttended']."</td>";

    echo "<td>".$row['AttendancePercentage']."</td>";

    $reg=$row['RegNo'];

    $CH=$row['ClassesHeld'];

    $CA=$row['ClassesAttended'];

    $per=($CA/$CH)*100;

    if($per<75)$status='YES';

    else $status='NO';

    echo "<td>".$status."</td></tr>";

   

    //Query for updation with calculated percentage.

         $query1 = mysql_query("update prog13 set AttendancePercentage='".$per."'where RegNo='".$reg."';",$connection);

    //Query to reset AttendancePercentage to zero.

         //$query1 = mysql_query("update prog13 set AttendancePercentage=0 where RegNo='".$reg."';",$connection);

}

echo "<table border=3>";

echo "<br><b>MySQL table updated successfully.</b>";

mysql_close($connection); // Closing Connection with Server

?>

</body>

</html>

Sunday, 23 January 2022

13. PHP Program to read data from MySQL table and Calculate attendance percentage

<!-- 13. PHP Program to read data from MySQL table and calculate attendance percentage -->
<html>
<head>
<title>Read data and update mysql table using php </title>
</head>
<body bgcolor=gray text=yellow>
<?php

$connection = mysql_connect("localhost", "root", ""); // Establish Connection with Server
$db = mysql_select_db("test", $connection); // Selecting Database
//MySQL Query to read data
$query = mysql_query("select * from prog13", $connection);
echo "<h3>Student Attendance Details</h3>";
echo "<table border=3 cellspacing=5>";
echo"<tr><th>RegNo</th><th>StudentName</th><th>Subject</th><th>ClassesHeld</th><th>ClassesAttended</th><th>AttendancePercentage</th></tr>";
while ($row = mysql_fetch_array($query))
{
    echo "<tr><td>".$row['RegNo']."</td>";
    echo "<td>".$row['StudentName']."</td>";
    echo "<td>".$row['Subject']."</td>";
    echo "<td>".$row['ClassesHeld']."</td>";
    echo "<td>".$row['ClassesAttended']."</td>";
    echo "<td>".$row['AttendancePercentage']."</td></tr>";

    $reg=$row['RegNo'];
    $CH=$row['ClassesHeld'];
    $CA=$row['ClassesAttended'];
    $per=($CA/$CH)*100;
    
    //Query for updation with calculated percentage.
        $query1 = mysql_query("update prog13 set AttendancePercentage='".$per."'where RegNo='".$reg."';",$connection);
    //Query to reset AttendancePercentage to zero.
        //$query1 = mysql_query("update prog13 set AttendancePercentage=0 where RegNo='".$reg."';",$connection);
    
}
echo "<table border=3>";
echo "<br><b>MySQL table updated successfully.</b>";
//Query for inserting values in prog13 table.
        //$query1 = mysql_query("insert into prog13 values('123','abcd','sub1',20,16,0);",$connection);
mysql_close($connection); // Closing Connection with Server
?>
</body>
</html>

12. PHP Program to read text file and display data using TABLE tag.

 <!-- 12. PHP Program to read text file and display data using <table> tag. -->
<html>

   <head>
      <title>Reading a file using PHP</title>
   </head>
   <?php
        // Turn off all error reporting
    error_reporting(0);
    ?>

    <body bgcolor=green text=white>
      
    <?php
           $fp = fopen('D:\\php.txt', 'r');
         
         if( $fp == false )
         {
            echo ( "<h3>File not found!</h3>" );
            exit();
         }
         
           $delimiter='#';

            echo "<h3>Salary Details of Employees:</h3>";
            print_r("<table border=3>");
            print_r("<tr><th>EmpId</th><th>EmployeeName</th><th>Designation</th><th>Department</th>
            <th>BasicSalary</th><th>Allowance</th><th>Deduction</th><th>GrossSalary</th><th>NetSalary</th></tr>");
            while ( !feof($fp) )
            {
                $line = fgets($fp, 1024);

                $data = str_getcsv($line, $delimiter);
                   
                $eid=$data[0];
                $ename=$data[1];
                $desig=$data[2];
                $dept=$data[3];
                $bsal=$data[4];
                $all=$data[5];
                $ded=$data[6];
                $gsal=$bsal+$all;
                $nsal=$gsal-$ded;
                print_r("<tr>");
                print_r("<td>".$eid. "</td>");
                print_r("<td>".$ename. "</td>");
                print_r("<td>".$desig. "</td>");
                print_r("<td>".$dept. "</td>");
                print_r("<td>".$bsal. "</td>");
                print_r("<td>".$all. "</td>");
                print_r("<td>".$ded. "</td>");
                print_r("<td>".$gsal. "</td>");
                print_r("<td>".$nsal. "</td>");
                echo "</tr>";
            }              
            echo "</table>";
      ?>
      
   </body>
</html>

Thursday, 30 August 2018

2. Write a program to upload and display an image using PHP.
 <HTML>
<HEAD>
<TITLE>PHP PROGRAM TO UPLOAD A FILE.</TITLE>
</HEAD>
<BODY>

<FORM ACTION="fileupload.php" ENCTYPE="MULTIPART/FORM-DATA" METHOD="POST">
<b>Select the Image to upload:</b>
<INPUT TYPE="file" NAME="file"><BR/>
<INPUT TYPE="Submit" VALUE="Upload" NAME="Upload"> <BR/>
</FORM>

<?php
if(isset($_POST['Upload']))
{
    $path = "photos/" . $_FILES["file"]["name"];

    if(move_uploaded_file($_FILES["file"]["tmp_name"], $path))
    {
        echo "<img src=",$path," height=250 width=500 >";
    }
    else
    {
        echo "Error!";
    }
}
?>

</BODY>
</HTML>

1. Write a program to connect the mysql-database and display connection status using PHP.

1. Write a program to connect the mysql-database and display connection status using PHP.
<HTML>
<HEAD>
<TITLE> MYSQL Connection Status</TITLE>
</HEAD>
<BODY BGCOLOR="BEIGE" SIZE=22 TEXT=BLUE>
<?php
$servername = "localhost";
$username = "man";
$password = "";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error)
{
    die("Connection failed: " . $conn->connect_error);
}
echo "MySQL Connected successfully.";
?>
</BODY>
</HTML>
FREE Hit Counters