DWPD - Practicals
PRACTICAL 1: Display Image and Hyperlinking
Aim: Write HTML codes for displaying image and demonstrate hyperlinking
<!DOCTYPE html>
<html>
<head>
<title>Practical 1 - Image and Hyperlink</title>
</head>
<body>
<h2>Demonstration of Image and Hyperlink</h2>
<p>Click the image below to visit Example Website:</p>
<a href="https://www.example.com" target="_blank">
<img src="https://via.placeholder.com/150" alt="Sample Image" width="150" height="150">
</a>
<p><a href="https://www.google.com">Go to Google Search</a></p>
</body>
</html>
PRACTICAL 2: Attach Video Using Embed Tag
Aim: Write HTML codes to attach video on webpage using embed tag in html
<!DOCTYPE html>
<html>
<head>
<title>Practical 2 - Embed Video</title>
</head>
<body>
<h2>Embedding Video in HTML</h2>
<embed src="sample_video.mp4" type="video/mp4" width="500" height="300">
</body>
</html>
PRACTICAL 3: Feedback Form
Aim: Create A Feedback Form Using Form handling
<!DOCTYPE html>
<html>
<head>
<title>Practical 3 - Feedback Form</title>
</head>
<body>
<h2>Feedback Form</h2>
<form action="" method="POST">
<label for="name">Name:</label><br>
<input type="text" id="name" name="name" required><br><br>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email" required><br><br>
<label for="feedback">Feedback:</label><br>
<textarea id="feedback" name="feedback" rows="4" cols="30" required></textarea><br><br>
<input type="submit" name="submit" value="Submit Feedback">
</form>
</body>
</html>
PRACTICAL 4: Contact Form
Aim: Create a contact form using form handling
<!DOCTYPE html>
<html>
<head>
<title>Practical 4 - Contact Form</title>
</head>
<body>
<h2>Contact Us</h2>
<form action="" method="POST">
<label>Full Name:</label><br>
<input type="text" name="fullname" required><br><br>
<label>Phone Number:</label><br>
<input type="tel" name="phone" required><br><br>
<label>Subject:</label><br>
<input type="text" name="subject" required><br><br>
<label>Message:</label><br>
<textarea name="message" rows="5" cols="40" required></textarea><br><br>
<input type="submit" value="Send Message">
</form>
</body>
</html>
PRACTICAL 5: Static Page Layout Using Division Tag
Aim: Write a code for creating static page design using division tag
<!DOCTYPE html>
<html>
<head>
<title>Practical 5 - Layout with Divs</title>
<style>
.header { background-color: #4CAF50; color: white; text-align: center; padding: 15px; }
.sidebar { background-color: #f1f1f1; width: 25%; float: left; height: 200px; padding: 10px; }
.content { background-color: #e2e2e2; width: 70%; float: right; height: 200px; padding: 10px; }
.footer { background-color: #333; color: white; text-align: center; padding: 10px; clear: both; }
</style>
</head>
<body>
<div class="header"><h1>Header Section</h1></div>
<div class="sidebar"><p>Sidebar Menu</p></div>
<div class="content"><p>Main Content Area</p></div>
<div class="footer"><p>Footer Section</p></div>
</body>
</html>
PRACTICAL 6: Menu System Using List Tag
Aim: Write a code for design menu system using list tag
<!DOCTYPE html>
<html>
<head>
<title>Practical 6 - Menu System</title>
<style>
ul.nav { list-style-type: none; margin: 0; padding: 0; background-color: #333; overflow: hidden; }
ul.nav li { float: left; }
ul.nav li a { display: block; color: white; text-align: center; padding: 14px 16px; text-decoration: none; }
ul.nav li a:hover { background-color: #111; }
</style>
</head>
<body>
<ul class="nav">
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</body>
</html>
PRACTICAL 7: Design Google Homepage Using HTML5
Aim: Design Google Page using HTML5
<!DOCTYPE html>
<html>
<head>
<title>Google Clone</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; margin-top: 150px; }
.logo { font-size: 70px; font-weight: bold; }
.blue { color: #4285F4; }
.red { color: #EA4335; }
.yellow { color: #FBBC05; }
.green { color: #34A853; }
.search-box { width: 400px; height: 30px; border-radius: 20px; border: 1px solid #ccc; padding: 5px 15px; margin-top: 20px; }
.btn { margin-top: 20px; padding: 8px 16px; border: none; background-color: #f8f9fa; cursor: pointer; }
</style>
</head>
<body>
<div class="logo">
<span class="blue">G</span><span class="red">o</span><span class="yellow">o</span><span class="blue">g</span><span class="green">l</span><span class="red">e</span>
</div>
<input type="text" class="search-box"><br>
<button class="btn">Google Search</button>
<button class="btn">I'm Feeling Lucky</button>
</body>
</html>
PRACTICAL 8: Apply CSS Formatting
Aim: Apply CSS formatting to created pages and explore it fully
<!DOCTYPE html>
<html>
<head>
<title>Practical 8 - CSS Styles</title>
<style>
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f4f4f9; }
.styled-card { background: white; width: 300px; padding: 20px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); margin: 50px auto; }
.styled-card h3 { color: #333; border-bottom: 2px solid #007BFF; padding-bottom: 5px; }
</style>
</head>
<body>
<div class="styled-card">
<h3>CSS Card Component</h3>
<p>This element is styled using internal CSS properties including shadows, border-radius, and font styling.</p>
</div>
</body>
</html>
PRACTICAL 9: PHP Welcome Message
Aim: Write a PHP script to display Welcome message
<?php
// Practical 9: Display Welcome Message
echo "<h1>Welcome to Dynamic Web Page Development Lab!</h1>";
?>
PRACTICAL 10: PHP Operators Demonstration
Aim: Write a PHP script to demonstrate use of arithmetic operators, comparison operators, and logical operators
<?php
$a = 10;
$b = 5;
// Arithmetic Operators
echo "<h3>Arithmetic Operators</h3>";
echo "Addition (10 + 5): " . ($a + $b) . "<br>";
echo "Subtraction (10 - 5): " . ($a - $b) . "<br>";
// Comparison Operators
echo "<h3>Comparison Operators</h3>";
echo "Is Equal (10 == 5): " . var_export($a == $b, true) . "<br>";
echo "Is Greater Than (10 > 5): " . var_export($a > $b, true) . "<br>";
// Logical Operators
echo "<h3>Logical Operators</h3>";
echo "Logical AND (true && false): " . var_export(($a > 5 && $b > 10), true) . "<br>";
echo "Logical OR (true || false): " . var_export(($a > 5 || $b > 10), true) . "<br>";
?>
PRACTICAL 11: Variable Type Detection (gettype)
Aim: Write a PHP script to get type of variable using gettype()
<?php
$var1 = 100;
$var2 = 45.67;
$var3 = "Hello World";
$var4 = true;
echo "Type of \$var1: " . gettype($var1) . "<br>";
echo "Type of \$var2: " . gettype($var2) . "<br>";
echo "Type of \$var3: " . gettype($var3) . "<br>";
echo "Type of \$var4: " . gettype($var4) . "<br>";
?>
PRACTICAL 12: Set Variable Type (settype)
Aim: Write a PHP script to set type of variable using settype()
<?php
$var = 32.5;
echo "Original Type: " . gettype($var) . " (Value: $var)<br>";
settype($var, "integer");
echo "New Type: " . gettype($var) . " (Value: $var)<br>";
settype($var, "string");
echo "New Type: " . gettype($var) . " (Value: $var)<br>";
?>
PRACTICAL 13: Variable Type Casting
Aim: Write a PHP script to set type of variable using type casting
<?php
$floatVal = 99.99;
$intVal = (int)$floatVal;
$stringVal = (string)$floatVal;
echo "Original Value: " . $floatVal . " (" . gettype($floatVal) . ")<br>";
echo "Cast to Integer: " . $intVal . " (" . gettype($intVal) . ")<br>";
echo "Cast to String: " . $stringVal . " (" . gettype($stringVal) . ")<br>";
?>
PRACTICAL 14: Fibonacci Series in PHP
Aim: Write PHP Script to print Fibonacci series
<?php
$n = 10;
$n1 = 0;
$n2 = 1;
echo "Fibonacci Series (First $n terms): <br>";
echo $n1 . " " . $n2 . " ";
for ($i = 2; $i < $n; $i++) {
$n3 = $n1 + $n2;
echo $n3 . " ";
$n1 = $n2;
$n2 = $n3;
}
?>
PRACTICAL 15: Student Marks & Grade Calculation
Aim: Write PHP Script to calculate total marks of student and display grade
<?php
$m1 = 85;
$m2 = 78;
$m3 = 92;
$total = $m1 + $m2 + $m3;
$percentage = $total / 3;
echo "Total Marks: $total / 300<br>";
echo "Percentage: " . number_format($percentage, 2) . "%<br>";
if ($percentage >= 80) {
echo "Grade: Distinction";
} elseif ($percentage >= 60) {
echo "Grade: First Class";
} elseif ($percentage >= 40) {
echo "Grade: Pass";
} else {
echo "Grade: Fail";
}
?>
PRACTICAL 16: Maximum of Three Numbers
Aim: Write PHP Script to find maximum number out of three given numbers
<?php
$a = 45;
$b = 78;
$c = 23;
if ($a >= $b && $a >= $c) {
$max = $a;
} elseif ($b >= $a && $b >= $c) {
$max = $b;
} else {
$max = $c;
}
echo "The maximum of $a, $b, and $c is: $max";
?>
PRACTICAL 17: Addition of Two 2x2 Matrices
Aim: Write PHP Script using two-dimensional arrays such as addition of two 2x2 matrices
<?php
$matrixA = [
[1, 2],
[3, 4]
];
$matrixB = [
[5, 6],
[7, 8]
];
$result = [];
for ($i = 0; $i < 2; $i++) {
for ($j = 0; $j < 2; $j++) {
$result[$i][$j] = $matrixA[$i][$j] + $matrixB[$i][$j];
}
}
echo "<h3>Matrix Addition Result:</h3>";
for ($i = 0; $i < 2; $i++) {
for ($j = 0; $j < 2; $j++) {
echo $result[$i][$j] . " ";
}
echo "<br>";
}
?>
PRACTICAL 18: Associative Arrays & Foreach Loop
Aim: Write PHP Script to demonstrate use of associative arrays and for FOR EACH loop execution
<?php
$student_ages = [
"Alice" => 20,
"Bob" => 22,
"Charlie" => 21
];
echo "<h3>Student Age List:</h3>";
foreach ($student_ages as $name => $age) {
echo "Name: " . $name . ", Age: " . $age . "<br>";
}
?>
PRACTICAL 19: User-Defined Functions in PHP
Aim: Write PHP script Using user defined function
<?php
function calculateArea($length, $width) {
return $length * $width;
}
$l = 10;
$w = 5;
$area = calculateArea($l, $w);
echo "Area of rectangle ($l x $w) = " . $area;
?>
PRACTICAL 20: String Functions
Aim: Write PHP script to demonstrate use of string function
<?php
$str = "Hello Dynamic Web Page!";
echo "Original String: " . $str . "<br>";
echo "String Length: " . strlen($str) . "<br>";
echo "Word Count: " . str_word_count($str) . "<br>";
echo "Reversed String: " . strrev($str) . "<br>";
echo "Uppercase: " . strtoupper($str) . "<br>";
echo "Replace 'Dynamic' with 'PHP': " . str_replace("Dynamic", "PHP", $str) . "<br>";
?>
PRACTICAL 21: Date/Time and Math Functions
Aim: Write PHP script to demonstrate use of date/time functions and Math functions
<?php
echo "<h3>Date/Time Functions</h3>";
echo "Current Date: " . date("Y-m-d") . "<br>";
echo "Current Time: " . date("h:i:s A") . "<br>";
echo "<h3>Math Functions</h3>";
echo "Absolute Value of -15: " . abs(-15) . "<br>";
echo "Square Root of 64: " . sqrt(64) . "<br>";
echo "Power (2^5): " . pow(2, 5) . "<br>";
echo "Round (4.6): " . round(4.6) . "<br>";
?>
PRACTICAL 22: Complete Form Processing
Aim: Create form using text box, check box, radio button, select, submit button. And display user inserted value in new PHP page
File 1: form.html
<!DOCTYPE html>
<html>
<head><title>Registration Form</title></head>
<body>
<h2>Student Registration Form</h2>
<form action="process.php" method="POST">
Name: <input type="text" name="username" required><br><br>
Gender:
<input type="radio" name="gender" value="Male"> Male
<input type="radio" name="gender" value="Female"> Female<br><br>
Hobbies:
<input type="checkbox" name="hobby[]" value="Reading"> Reading
<input type="checkbox" name="hobby[]" value="Coding"> Coding<br><br>
City:
<select name="city">
<option value="Ahmedabad">Ahmedabad</option>
<option value="Surat">Surat</option>
</select><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
File 2: process.php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
echo "<h2>Submitted Data</h2>";
echo "Name: " . htmlspecialchars($_POST['username']) . "<br>";
echo "Gender: " . (isset($_POST['gender']) ? $_POST['gender'] : 'Not specified') . "<br>";
echo "Hobbies: " . (isset($_POST['hobby']) ? implode(", ", $_POST['hobby']) : 'None') . "<br>";
echo "City: " . $_POST['city'] . "<br>";
}
?>
PRACTICAL 23: Passing Variables Through URL
Aim: Write two different PHP script to demonstrate passing variables through a URL
File 1: page1.php
<?php
$name = "John";
$role = "Admin";
echo "<a href='page2.php?user=" . urlencode($name) . "&role=" . urlencode($role) . "'>Send Data via URL</a>";
?>
File 2: page2.php
<?php
$user = $_GET['user'] ?? 'Guest';
$role = $_GET['role'] ?? 'None';
echo "User: " . htmlspecialchars($user) . "<br>";
echo "Role: " . htmlspecialchars($role) . "<br>";
?>
PRACTICAL 24: Passing Variables via Hidden Form Fields
Aim: Write two different PHP script to demonstrate passing variables through Hidden Variables
File 1: step1.php
<form action="step2.php" method="POST">
<label>Enter Name:</label>
<input type="text" name="username"><br>
<input type="hidden" name="session_id" value="SESS12345">
<input type="submit" value="Next">
</form>
File 2: step2.php
<?php
$username = $_POST['username'];
$session_id = $_POST['session_id'];
echo "Name: " . htmlspecialchars($username) . "<br>";
echo "Hidden Session ID: " . htmlspecialchars($session_id) . "<br>";
?>
PRACTICAL 25: Session Management
Aim: Write two different PHP script to demonstrate passing variables with sessions
File 1: set_session.php
<?php
session_start();
$_SESSION["username"] = "Alice";
$_SESSION["role"] = "Developer";
echo "Session variables are set. <a href='get_session.php'>Go to Next Page</a>";
?>
File 2: get_session.php
<?php
session_start();
if (isset($_SESSION["username"])) {
echo "Welcome, " . $_SESSION["username"] . "<br>";
echo "Role: " . $_SESSION["role"];
} else {
echo "No active session found.";
}
?>
PRACTICAL 26: Cookie Management
Aim: Write PHP script to demonstrate passing variables with cookies
<?php
// Setting cookie
setcookie("user", "JohnDoe", time() + (86400 * 30), "/"); // 1 day expiration
if (isset($_COOKIE["user"])) {
echo "Cookie 'user' value: " . $_COOKIE["user"];
} else {
echo "Cookie 'user' is not set yet. Refresh the page.";
}
?>
PRACTICAL 27: Page Load Counter
Aim: Write a program to keep track of how many times a visitor has loaded the page
<?php
session_start();
if (!isset($_SESSION['views'])) {
$_SESSION['views'] = 1;
} else {
$_SESSION['views']++;
}
echo "You have visited this page " . $_SESSION['views'] . " time(s) during this session.";
?>
PRACTICAL 28: Image Upload with File Extension Validation
Aim: Write a Program to upload image with extension gif or jpeg
<?php
if (isset($_POST["submit"])) {
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
if ($imageFileType == "jpg" || $imageFileType == "jpeg" || $imageFileType == "gif") {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file " . htmlspecialchars(basename($_FILES["fileToUpload"]["name"])) . " has been uploaded.";
} else {
echo "Error uploading file.";
}
} else {
echo "Only JPG, JPEG, & GIF files are allowed.";
}
}
?>
<form action="" method="post" enctype="multipart/form-data">
Select Image to Upload (.gif, .jpeg):
<input type="file" name="fileToUpload" required>
<input type="submit" value="Upload Image" name="submit">
</form>
PRACTICAL 29: Image Watermark
Aim: Write a PHP script to create watermarks using Image copy merge
<?php
$stamp = imagecreatefrompng('watermark.png');
$im = imagecreatefromjpeg('photo.jpg');
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, $sx, $sy, 50);
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
PRACTICAL 30: Image Grayscale Conversion
Aim: Write a PHP script to convert images to grayscale
<?php
$im = imagecreatefromjpeg('photo.jpg');
if ($im && imagefilter($im, IMG_FILTER_GRAYSCALE)) {
header('Content-Type: image/jpeg');
imagejpeg($im);
imagedestroy($im);
} else {
echo 'Conversion to grayscale failed.';
}
?>
PRACTICAL 31: MySQL Connection
Aim: Write a PHP script to connect MYSQL server from your web application
<?php
$servername = "localhost";
$username = "root";
$password = "";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully to MySQL server";
$conn->close();
?>
PRACTICAL 32: Create and Drop Database
Aim: Write a PHP script to create and drop database
<?php
$conn = new mysqli("localhost", "root", "");
// Create Database
$sqlCreate = "CREATE DATABASE test_db";
if ($conn->query($sqlCreate) === TRUE) {
echo "Database created successfully<br>";
}
// Drop Database
$sqlDrop = "DROP DATABASE test_db";
if ($conn->query($sqlDrop) === TRUE) {
echo "Database dropped successfully";
}
$conn->close();
?>
PRACTICAL 33: Database Setup via phpMyAdmin
Aim: Create database using phpMyAdmin
Steps:
Open XAMPP/WAMP Control Panel and start Apache and MySQL services.
Open your web browser and navigate to
http://localhost/phpmyadmin.Click on the Databases tab on the top menu bar.
Under Create database, enter database name (e.g.,
student_db).Choose collation
utf8_general_ciand click Create.Create table
studentswith fields:id(INT, Primary Key, Auto Increment),name(VARCHAR),email(VARCHAR).
PRACTICAL 34: Read & Display MySQL Data in HTML Table
Aim: Write a program to read input data, from table and display all these information in tabular form on output screen
<?php
$conn = new mysqli("localhost", "root", "", "student_db");
$sql = "SELECT id, name, email FROM students";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table border='1'><tr><th>ID</th><th>Name</th><th>Email</th></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["id"]."</td><td>".$row["name"]."</td><td>".$row["email"]."</td></tr>";
}
echo "</table>";
} else {
echo "0 results found";
}
$conn->close();
?>
PRACTICAL 35: Data Manipulation (INSERT/UPDATE/DELETE)
Aim: Write a program to manipulate data from table and display all this information using table format
<?php
$conn = new mysqli("localhost", "root", "", "student_db");
// Insert Record
$conn->query("INSERT INTO students (name, email) VALUES ('John Doe', 'john@example.com')");
// Update Record
$conn->query("UPDATE students SET email='john_new@example.com' WHERE name='John Doe'");
// Display Records
$result = $conn->query("SELECT * FROM students");
echo "<table border='1'><tr><th>ID</th><th>Name</th><th>Email</th></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["id"]."</td><td>".$row["name"]."</td><td>".$row["email"]."</td></tr>";
}
echo "</table>";
$conn->close();
?>
PRACTICAL 36: Mini Application (Form + Database)
Aim: Develop small PHP application(s) using forms and database
<?php
$conn = new mysqli("localhost", "root", "", "student_db");
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$conn->query("INSERT INTO students (name, email) VALUES ('$name', '$email')");
}
?>
<!DOCTYPE html>
<html>
<head><title>Student Portal Application</title></head>
<body>
<h2>Add New Student</h2>
<form action="" method="POST">
Name: <input type="text" name="name" required><br><br>
Email: <input type="email" name="email" required><br><br>
<input type="submit" name="submit" value="Register Student">
</form>
<h2>Registered Students</h2>
<?php
$result = $conn->query("SELECT * FROM students");
echo "<table border='1'><tr><th>ID</th><th>Name</th><th>Email</th></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["id"]."</td><td>".$row["name"]."</td><td>".$row["email"]."</td></tr>";
}
echo "</table>";
$conn->close();
?>
</body> </html>
Comments
Post a Comment