SRI KRISHNA ARTS & SCIENCE COLLEGE
An Autonomous college affiliated to Bharathiar University
DEPARTMENT OF COMPUTER APPLICATIONS
LABORATORY RECORD
NAME : _________________________
REGISTER NUMBER : _________________________
CLASS : _________________________
SRI KRISHNA ARTS & SCIENCE COLLEGE
An Autonomous college affiliated to Bharathiar University
Practical: Web Designing using PHP
(23SAU28)
REGISTER NUMBER
Certified-Bonafide Record work done by in
during the year 2024 – 2025.
Staff-in-charge Head of the Department
Submitted to the SRI KRISHNA ARTS AND SCIENCE COLLEGE End Semester
Examination held on / / 2025
Examiners
External
Internal
SRI KRISHNA ARTS & SCIENCE COLLEGE
An Autonomous college affiliated to Bharathiar University
Practical: Web Designing using PHP
(23CAU28)
REGISTER NUMBER
Certified-Bonafide Record work done by in
during the year 2024 – 2025.
Staff-in-charge Head of the Department
Submitted to the SRI KRISHNA ARTS AND SCIENCE COLLEGE End Semester
Examination held on / / 2025
Examiners
External
Internal
DECLARATION
I hereby declare that this
record of observations is based on the experiments carried out and recorded by me
during the laboratory classes of Practical: Web Designing using PHP conducted
by Sri Krishna Arts and Science College, Coimbatore – 641008.
Date:
Signature of the Student
Name of the Student :
Register Number :
Countersigned by Staff
INDEX
Page
S.No Date Name of the Program Signature
No.
1 03/12/2024 Decision-making Statements
2 03/12/2024 Looping Statements
3 10/12/2024 User-defined Functions
4 17/12/2024 String and Date Built-In Functions
5 23/01/2025 Arrays and its Operations
6 23/01/2025 Method Overriding and Inheritance
7 06/02/2025 File Operations
8 17/02/2025 CRUD operations using MySQL phpMyAdmin
9 24/02/2025 Login Web Page
10 03/03/2025 Employee Info Web Form with MySQL Storage
Display The Selected Item in Separate Web Page
11 10/03/2025
Using Cookies
12 10/03/2025 Login Web Page Using Session
Ex. No:1
Decision-making Statements
03.12.2024
PROGRAM:
<?php
$name = "John Doe";
$maths = 80;
$english = 75;
$science = 90;
$total = $maths + $english + $science;
// Using if-else statement to find pass/fail status
if ($total >= 120) {
echo "$name has passed!<br>";
} else {
echo "$name has failed.<br>";
}
if ($total >= 240) {
echo "He has passed with a Distinction!<br>";
}
// Using elseif statement to find grade
$avg = $total / 3;
if ($avg >= 80) {
echo "He has received an A grade!<br>";
} elseif ($avg >= 60) {
echo "He has received a B grade.<br>";
} elseif ($avg >= 40) {
echo "He has received a C grade.<br>";
} else {
echo "He has received a D grade.<br>";
}
// Using switch statement to find subject-wise grades
echo "Subject-wise grades for $name:<br>";
switch ($maths) {
case $maths >= 80:
echo "Maths: A<br>";
break;
case $maths >= 60:
echo "Maths: B<br>";
break;
case $maths >= 40:
echo "Maths: C<br>";
break;
default:
echo "Maths: D<br>";
}
switch ($english) {
case $english >= 80:
echo "English: A<br>";
break;
case $english >= 60:
echo "English: B<br>";
break;
case $english >= 40:
echo "English: C<br>";
break;
default:
echo "English: D<br>";
}
switch ($science) {
case $science >= 80:
echo "Science: A<br>";
break;
case $science >= 60:
echo "Science: B<br>";
break;
case $science >= 40:
echo "Science: C<br>";
break;
default:
echo "Science: D<br>";
}
?>
OUTPUT:
RESULT:
Ex. No:2
Looping Statements
03.12.2024
PROGRAM:
<?php
//Fibonacci series using while loop
$num1 = 0;
$n1 = 0;
$n2 = 1;
echo "Fibonacci series for first 12 numbers:<br>";
echo $n1 . " " . $n2;
while ($num1 < 10) {
$n3 = $n2 + $n1;
echo $n3 . " ";
$n1 = $n2;
$n2 = $n3;
$num1 = $num1 + 1;
}
//Factorial using do while loop
$num2 = 12;
$factorial = 1;
$i = 1;
do {
$factorial *= $i;
$i++;
} while ($i <= $num2);
echo "<br><br>The factorial of $num2 is $factorial.<br><br>";
//To find Armstrong number using for loop
$n = 371;
$sum = 0;
for ($i = $n; $i != 0; $i = $i / 10) {
$x = $i % 10;
$sum = $sum + $x * $x * $x;
}
if ($n == $sum) {
echo "$n is an Armstrong Number.<br><br>";
} else {
echo "$n is not an Armstrong Number.<br><br>";
}
//Printing season using foreach
$season = ["Winter", "Summer", "Spring", "Autumn", "Raining"];
echo "All Season name:";
foreach ($season as $element) {
echo "<br>";
echo "->$element";
}
?>
OUTPUT:
RESULT:
Ex. No:3
User-defined Functions
10.12.2024
PROGRAM:
<?php
//User-Defined Function
function add($x, $y)
{
$sum = $x + $y;
echo "Sum = $sum <br><br>";
}
function sub($x, $y)
{
$sub = $x - $y;
echo "Diff = $sub <br><br>";
}
if (isset($_POST["add"])) {
add($_POST["first"], $_POST["second"]);
}
if (isset($_POST["sub"])) {
sub($_POST["first"], $_POST["second"]);
}
?>
<form method="post">
Enter first number: <input type="number" name="first"/><br><br>
Enter second number: <input type="number" name="second"/><br><br>
<input type="submit" name="add" value="ADDITION"/>
<input type="submit" name="sub" value="SUBTRACTION"/>
</form>
OUTPUT:
RESULT:
Ex. No:4
String and Date Built-In Functions
17.12.2024
PROGRAM:
<!DOCTYPE html>
<html>
<body>
<?php
$str = "An Example String";
$res1 = strlen($str);
$res2 = str_word_count($str);
printf("Your string lenght is %d. <br>
Your string words count: %d" . "<br><br>",$res1,$res2);
echo ucwords($str) . "<br>";
echo strtolower($str) . "<br>";
echo strtoupper($str) . "<br>";
echo str_shuffle($str) . "<br>";
echo "Created Date: " . date("l, d/m/Y"). "<br>"
?>
</body>
</html>
OUTPUT:
RESULT:
Ex. No:5
Arrays and its Operations
23.01.2025
PROGRAM:
<?php
$a1 = array(array(4, 6, 7),array(3, 9, 9),array(5, 4, 8));
$a2 = array(array(6, 7, 5),array(9, 2, 1),array(6, 8, 3));
$row = count($a1);
$col = count($a1[0]);
echo "First matrix:<br>";
for ($i = 0; $i < $row; $i++) {
for ($j = 0; $j < $col; $j++) {
echo $a1[$i][$j] . " ";
}
echo "<br>";
}
echo "Second matrix:<br>";
for ($i = 0; $i < $row; $i++) {
for ($j = 0; $j < $col; $j++) {
echo $a2[$i][$j] . " ";
}
echo "<br>";
}
$sum = array();
for ($i = 0; $i < $row; $i++) {
for ($j = 0; $j < $col; $j++) {
$sum[$i][$j] = $a1[$i][$j] + $a2[$i][$j];
}
}
echo "Addition of two matrices: <br>";
for ($i = 0; $i < $row; $i++) {
for ($j = 0; $j < $col; $j++) {
echo $sum[$i][$j] . " ";
}
echo "<br>";
}
echo "<br>";
//Associative Array
$details =
array("Name"=>"Alex","Email"=>"[email protected]","Age"=>21,"Gender"=>"Male",
"Salary"=>"₹50,000");
foreach ($details as $key => $element)
{
echo $key.": ". $element;
echo "<br>";
}
?>
OUTPUT:
RESULT:
Ex. No:6
Method Overriding and Inheritance
23.01.2025
PROGRAM:
<?php
class Person
{
function introduce(){
echo "I am a person.<br>";
}
}
class John extends Person
{
function introduce(){
echo "Hi, I am John.<br>";
}
}
class Mary extends Person
{
function introduce(){
echo "Hi, I am Mary.<br>";
}
}
$john = new John();
$mary = new Mary();
$john->introduce();
$mary->introduce();
?>
OUTPUT:
RESULT:
Ex. No:7
File Operations
06.02.2025
PROGRAM:
<?php
$filename = "Program6.txt";
$content = "Hello, this is a simple PHP file handling example.\nFile handling includes
creating, reading, and writing files.";
$additionalContent = "\nAppending this line to the file.";
function handleFile($filename, $mode, $content = null) {
$file = fopen($filename, $mode);
if ($file) {
if ($content) fwrite($file, $content);
else while (!feof($file)) echo nl2br(fgets($file));
fclose($file);
return true;
}
return false;
}
echo "<html><body>";
handleFile($filename, "w", $content);
handleFile($filename, "a", $additionalContent);
echo "<h3>File contents:</h3>";
handleFile($filename, "r");
echo "</body></html>";
?>
OUTPUT:
RESULT:
Ex. No:8
CRUD operations using MySQL phpMyAdmin
17.02.2025
PROGRAM:
<?php
$conn = new mysqli('localhost', 'root', '', 'testdb');
if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);
$name = "Alice Johnson";
$email = "[email protected]";
$id = 3;
// Insert if email doesn't exist
$conn->query("INSERT INTO users (name, email) SELECT '$name', '$email' WHERE
NOT EXISTS (SELECT id FROM users WHERE email='$email')")
? print("New record created successfully<br>")
: print("Error: Email already exists!<br>");
// Select & display users
$result = $conn->query("SELECT * FROM users");
while ($row = $result->fetch_assoc()) echo "ID: {$row['id']} – Name: {$row['name']} –
Email: {$row['email']}<br>";
// Update record
echo $conn->query("UPDATE users SET email='[email protected]' WHERE
id=$id") && $conn->affected_rows
? "Record updated successfully<br>"
: "No matching record found for update<br>";
// Delete record
echo $conn->query("DELETE FROM users WHERE id=$id") && $conn->affected_rows
? "Record deleted successfully<br>"
: "No matching record found for deletion<br>";
$conn->close();
?>
OUTPUT:
RESULT:
Ex. No:9
Login Web Page
24.02.2025
PROGRAM:
Login.php
<?php
session_start();
?>
<center>
<form action="Main.php" method="post" name="Login_Form">
<h3>Login</h3>
<div>
<label for="Username">Username: </label>
<input name="Username" type="text" class="Input" id="Username" required>
</div>
<br>
<div>
<label for="Password">Password: </label>
<input name="Password" type="password" class="Input" id="Password"
required>
</div>
<div>
<br>
<input name="Submit" type="submit" value="Login">
<input name="Reset" type="Reset" value="Reset">
</div>
</form>
</center>
Main.php
<?php
session_start();
?>
<html>
<body align="center" bgcolor="skyblue">
<h1>Welcome to PHP Programming</h1>
<form action="Login.php">
<input type="submit" value="Logout">
</form>
</body>
</html>
OUTPUT:
RESULT:
Ex.No:10
Employee Info Web Form with MySQL Storage
03.03.2025
PROGRAM:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "employee_db";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$ename = $_POST['ename'];
$designation = $_POST['designation'];
$department = $_POST['department'];
$salary = $_POST['salary'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$sql = "INSERT INTO employees (ename, designation, department, salary, email,
phone)
VALUES ('$ename', '$designation', '$department', '$salary', '$email', '$phone')";
if ($conn->query($sql) === TRUE) {
echo "<p style='color:green;'>New employee record added successfully.";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>Employee Information Form</title>
</head>
<body>
<h2>Enter Employee Information</h2>
<form method="post" action="">
Name: <input type="text" name="ename" required><br><br>
Designation: <input type="text" name="designation" required><br><br>
Department: <input type="text" name="department" required><br><br>
Salary: <input type="number" name="salary" required><br><br>
Email: <input type="email" name="email" required><br><br>
Phone Number: <input type="text" name="phone" required><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
OUTPUT:
RESULT:
Ex.No:11 Display The Selected Item in Separate Web Page
10.03.2025 Using Cookies
PROGRAM:
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Select Items</title>
</head>
<body bgcolor="grey">
<h1>Select Items</h1>
<form action="display.php" method="post">
<label>Select Fruit:</label><br>
<input type="checkbox" name="items[]" value="Apple"> Apple<br>
<input type="checkbox" name="items[]" value="Banana"> Banana<br>
<input type="checkbox" name="items[]" value="Mango"> Mango<br>
<br>
<label>Select Vegetable:</label><br>
<input type="checkbox" name="items[]" value="Carrot"> Carrot<br>
<input type="checkbox" name="items[]" value="Broccoli"> Broccoli<br>
<input type="checkbox" name="items[]" value="Spinach"> Spinach<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
display.php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['items'])) {
$selected_items = implode(", ", $_POST['items']); // Convert array to string
setcookie("selected_items", $selected_items, time() + 10, "/"); // Cookie expires in 10
seconds
// Redirect to avoid form resubmission
header("Location: " . $_SERVER['PHP_SELF']);
exit();
}
// Check if the cookie exists
if (isset($_COOKIE['selected_items'])) {
$selected_items = $_COOKIE['selected_items'];
} else {
$selected_items = "No items selected.";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Selected Items</title>
</head>
<body bgcolor="lightgreen">
<h2>Your Selected Items</h2>
<p>You Selected: <?php echo $selected_items; ?></p>
<br>
<a href="index.html">Go back</a>
</body>
</html>
OUTPUT:
RESULT:
Ex.No:12
Login Web Page Using Session
10.03.2025
PROGRAM:
index.php
<?php session_start();
if(!isset($_SESSION['UserData']['Username'])){
header("location:login.php");
exit;
}
?>
<html>
<body align="center" bgcolor="skyblue">
<h1>THE SESION IS USED IN THIS WEBPAGE</h1>
<form action="Logout.php">
<input type="submit" value="Logout">
</form>
</body>
</html>
login.php
<?php
session_start();
if (isset($_POST['Submit'])) {
$logins = ['Alex' => '123456', 'username1' => 'password1'];
$Username = $_POST['Username'] ?? '';
$Password = $_POST['Password'] ?? '';
if (isset($logins[$Username]) && $logins[$Username] == $Password) {
$_SESSION['UserData']['Username'] = $Username;
header("location:index.php");
exit;
} else {
$msg = "<span style='color:red'>Invalid Login Details</span>";
}
}
?>
<html>
<body bgcolor="lightgreen">
<center>
<form action="" method="post" name="Login_Form">
<?php if (isset($msg)) { ?>
<div><?php echo $msg; ?></div>
<?php } ?>
<h3>Login</h3>
<div>
<label for="Username">Username: </label>
<input name="Username" type="text" class="Input" id="Username">
</div>
<br>
<div>
<label for="Password">Password: </label>
<input name="Password" type="password" class="Input" id="Password">
</div>
<div>
<br>
<input name="Submit" type="submit" value="Login">
<input name="Reset" type="Reset" value="Reset">
</div>
</form>
</center>
</body>
</html>
logout.php
<?php session_start();
session_destroy();
header("location:login.php");
exit;
?>
OUTPUT:
RESULT: