kuchh
Practical 1
Using HTML tags create a web page using HTML tags and CSS..
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Static Webpage Example</title> <style> /* CSS styles can be included here */ table { width: 100%; border-collapse: collapse; } th,
td {
border: 1px solid black;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<header>
<h1>Welcome to My Static Webpage</h1>
<nav>
<ul>
<li><a href="#about">About</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section id="about">
<h2>About Us</h2>
<p>This is a sample static webpage demonstrating HTML tags, attributes, and a table.</p>
</section>
<section id="services">
<h2>Our Services</h2>
<ul>
<li>Web Development</li>
<li>Graphic Design</li>
<li>Content Writing</li>
</ul>
</section>
<section id="contact">
<h2>Contact Us</h2>
<address>
Email: <a href="[email protected]">[email protected]</a><br>
Phone: +91 8840100750<br>
Address: Old girls Hostel,Bharati vidyapeeth
</address>
</section>
<section>
<h2>Our Team</h2>
<table>
<tr>
<th>Name</th>
<th>Position</th>
</tr>
<tr>
<td>Richa</td>
<td>CEO</td>
</tr>
<tr>
<td>Abhimanyu</td>
<td>Designer</td>
</tr>
<tr>
<td>Aman</td>
<td>Developer</td>
</tr>
</table>
</section>
</main>
<footer>
<p>© 2024 My Static Webpage. All rights reserved.</p>
</footer>
</body>
</html>
Practical 2
Program to add two numbers in Php
<?php function addNumbers($num1, $num2) { return $num1 + $num2; } $number1 = 5; $number2 = 10; $sum = addNumbers($number1, $number2); echo "The sum of $number1 and $number2 is: $sum"; ?>Write a program to add two numbers in php using form
<!DOCTYPE html> <html> <head> <title>Addition Form</title> </head> <body> <h2>Addition Form</h2> <form method="post"> <label for="num1">Enter the first number:</label><br> <input type="number" id="num1" name="num1"><br><br> <label for="num2">Enter the second number:</label><br>
<input type="number" id="num2" name="num2"><br><br>
<input type="submit" value="Add">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
function addNumbers($num1, $num2) {
return $num1 + $num2;
}
$sum = addNumbers($num1, $num2);
echo "<p>The sum of $num1 and $num2 is: $sum</p>";
}
?>
</body>
</html>
Practical-03
Write a program in PHP to check whether a given number is odd or even.
<!DOCTYPE html> <html> <head> <title>Odd or Even Checker</title> </head> <body> <h2>Odd or Even Checker</h2> <form method="post"> <label for="number">Enter a number:</label><br> <input type="number" id="number" name="number"><br><br> <input type="submit" value="Check"> </form> <?php // Check if form is submitted if ($_SERVER["REQUEST_METHOD"] == "POST") { // Retrieve the number from the form $number = $_POST['number']; // Function to check if a number is odd or even function checkOddEven($num) { if ($num % 2 == 0) { return "$num is even."; } else { return "$num is odd."; } } // Check if the number is odd or even
$result = checkOddEven($number);
// Display the result
echo "<p>$result</p>";
}
?>
Program-02: Write a Php program to find out the maximum numbers among three numbers
<!DOCTYPE html> <html> <head> <title>Maximum of Three Numbers</title> </head> <body> <h2>Maximum of Three Numbers</h2> <form method="post"> <label for="num1">Enter the first number:</label><br> <input type="number" id="num1" name="num1"><br><br> <label for="num2">Enter the second number:</label><br>
<input type="number" id="num2" name="num2"><br><br>
<label for="num3">Enter the third number:</label><br>
<input type="number" id="num3" name="num3"><br><br>
<input type="submit" value="Find Maximum">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$num3 = $_POST['num3'];
function findMaximum(num2, num3) {
return max(num1, num3);
}
num1, num3);
echo "<p>The maximum of num2, and maximum</p>";
}
?>
Program-03: Write a PHP program to swap two numbers.
<!DOCTYPE html> <html> <head> <title>Number Swapper</title> </head> <body> <h2>Number Swapper</h2> <form method="post"> <label for="num1">Enter the first number:</label><br> <input type="number" id="num1" name="num1"><br><br> <label for="num2">Enter the second number:</label><br>
<input type="number" id="num2" name="num2"><br><br>
<input type="submit" value="Swap Numbers">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
echo "<p>Original numbers: num1 = $num1, num2 = $num2</p>";
function swapNumbers(&$a, &$b) {
$temp = $a;
$a = $b;
$b = $temp;
}
swapNumbers($num1, $num2);
echo "<p>After swapping: num1 = $num1, num2 = $num2</p>";
}
?>
</body>
</html>
Program 04: To write a program for find the given number is palindrome or not
<!DOCTYPE html> <html> <head> <title>Palindrome Checker</title> </head> <body> <h2>Palindrome Checker</h2> <form method="post"> <label for="number">Enter a number:</label><br> <input type="number" id="number" name="number"><br><br> <input type="submit" value="Check">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$number = $_POST['number'];
function isPalindrome($num)
$numStr = (string) $num;
$reversedStr = strrev($numStr);
if (reversedStr) {
return true;
} else {
return false;
}
}
if (isPalindrome(number)) {
echo "<p>number is a palindrome.</p>";
} else {
echo "<p>$number is not a palindrome.</p>";
}
}
?>
PROGRAM 5
To write a program for find the given number is Armstrong or not
Practical 06
Write a program to calculate the age of a person using form:
<?php
function calculateAge($dob) {
$dob_obj = new DateTime($dob);
$current_date = new DateTime();
$age = $dob_obj->diff($current_date)->y;
return $age;
}
if (_SERVER["REQUEST_METHOD"] == "POST") { if (isset(_POST["dob"]) && !empty(_POST["dob"])) { dob = $_POST["dob"];
$age = calculateAge($dob);
echo "<p>Your age is: " . $age . " years.</p>";
} else {
echo "<p>Please enter your date of birth.</p>";
}
}
?>
</body>
</html>
Practical 4
Problem Statement: Write a program to perform the following operations on an associative array. Display elements of an array along with their keys. Display size of array. Delete an element from an array from the given index.
A> Method 1- Run through Command Prompt Example 1 – Student And Roll no
Example 2 – Country And Capital
<?php echo "/n", "Display elements of associative array with both Key and Value strings" . "\n"; $Sgk = array( "India" => "Delhi", "Italy" => "Rome", "France" => "Paris", "Germany" => "Berlin", "Spain" => "Madrid", "United Kingdom" => "London" ); foreach($Sgk as $country => $Scapital) { echo "The capital of $country is $Scapital" . "\n"; } echo "\n" . "Display size of associative array" . "\n"; echo count($Sgk) . "\n"; echo "\n" . "Delete operation on associative array" . "\n"; echo "Associative array Before deleting the element" . "\n"; var_dump($Sgk); unset($Sgk["Spain"]); echo "\n" . "Associative Array After delete the element" . "\n"; var_dump($Sgk); ?> <?php $info = array("1" => "Kaushal", "2" => "Anupam", "3" => "Ritesh", "4" => "Raj Harsh Vardhan"); $ch = $_POST['a']; switch ($ch) { case 1: echo "<h3>Display Associative Array</h3>"; echo "The student Information: <br><br>"; echo "ROLL NO    STUDENT NAME <br>"; foreach ($info as $roll_num => $student_name) { echo "Key=$roll_num      value=$student_name <br>"; } break; case 2: echo "<h3>Display Size of Associative Array</h3>"; echo "The Size of Associative Array is <br><br>"; echo sizeof($info); break; case 3: echo "<h3>Delete Operation on Associative Array</h3>"; echo "Associative array Before deleting the element <br><br>"; var_dump($info); unset($info["1"]); // Assuming you want to delete the element with key "1" echo "<br><br>Associative array After deleting the element <br><br>"; var_dump($info); break; } ?>Program 4: Method through local host
<html> <body> <form action='p3.php' method='post'> <pre> <h3>OPERATIONS</h3> 1<input type='radio' name='a' value='1'>Display Array Elements.2<input type='radio' name='a' value='2'>Display
Size of
Array.
Array.
3<input type='radio' name='a' value='3'>Delete Element from
<input type='submit' value='ok'> <input type='reset'
value='cancel'>
</pre>
Practical 5
Create a login page and enter the data in the database and print the result of the inputted data on the screen:
Registeration.php
.main input[type="submit"] {
width: 95%;
border: 1px solid black;
padding: 1em;
}
.main input[type="password"] {
width: 95%;
border: 1px solid black;
padding: .5em;
margin: .5em;
}
.main input[type="text"],
.main input[type="email"] {
width: 40%;
border: 1px solid black;
padding: .5em;
margin: .5em;
}
</style>
</head>
<body>
<div class="main">
<form method="post" action="welcome.php">
<h2>
<center>Bharti Vidyapeeth(Deemed to be University) College of Engineering Pune</center>
</h2>
<h3>
<center>Student Registration</center>
</h3>
Name: <input type="text" name="fname" placeholder="First Name">
<input type="text" name="lname" placeholder="Last Name"><br><br>
Email: <input type="email" name="email" placeholder="Email"><br><br>
Contact No: <input type="text" name="mobile" placeholder="Mobile"><br><br>
City: <input type="text" name="city" placeholder="City"><br>
<hr>
Gender<br>
<input type="radio" name="gender" value="Male">Male <br>
<input type="radio" name="gender" value="Female">Female <br>
<hr>
<label for="branch">Choose Branch</label><br>
<select name="branch">
<option selected disabled>--select--</option>
<option value="Computer">Computer</option>
<option value="Computer Science and Engineering">Computer Science and Engineering</option>
<option value="Electronics">Electronics</option>
<option value="Mechanical">Mechanical</option>
</select><br>
<hr>
Hobbies <br>
<input type="checkbox" name="hobby[]" value="Cricket">Cricket <br>
<input type="checkbox" name="hobby[]" value="Football">Football <br>
<input type="checkbox" name="hobby[]" value="Chess">Chess <br>
<hr>
Enter Password <br>
<input type="Password" name="pass" placeholder="Password"> <br>
<br>
<input type="submit" name="submit" value="Register">
</form>
</div>
<?php
if(isset($_POST['submit'])){
$fn=$_POST['fname'];
$ln=$_POST['lname'];
$em=$_POST['email'];
$mob=$_POST['mobile'];
$city=$_POST['city'];
$gender=$_POST['gender'];
$sbranch=$_POST['branch'];
$hobbies=$_POST['hobby'];
$pass=$_POST['pass'];
echo "Student Name:- $fn $ln <br><br>";
echo "Email:- $em <br><br>";
echo "Mob:- $mob <br><br>";
echo "City:- $city <br><br>";
echo "Gender:- $gender <br><br>";
echo "Branch:- $sbranch <br><br>";
echo "<h3>Hobbies</h3>";
$i=0;
while($i<sizeof($hobbies)){
echo $hobbies[$i]."<br>";
$i++; }}?>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
</html>
Practical 6
Write a Program create PHP MySQL Login System
Index.html
<!DOCTYPE html> <html> <head> <title>PHP login system</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div id="frm"> <h1>Login</h1> <form name="f1" action="authentication.php" onsubmit="return validation()" method="POST"> <p> <label>UserName:</label> <input type="text" id="user" name="user" /> </p> <p> <label>Password:</label> <input type="password" id="pass" name="pass" /> </p> <p> <input type="submit" id="btn" value="Login" /> </p> </form> </div><script>
function validation() {
var id = document.f1.user.value;
var ps = document.f1.pass.value;
if (id.length === 0 && ps.length === 0) {
alert("User Name and Password fields are empty");
return false;
}
if (id.length === 0) {
alert("User Name is empty");
return false;
}
if (ps.length === 0) {
alert("Password field is empty");
return false;
}
return true;
}
</script>
</body>
</html>
Style.css
body{
background-color: #eee;
}
#frm{
border: solid gray 1px;
width: 25%;
border-radius: 2px;
margin: 120px auto;
background-color: white;
padding: 50px;
}
#btn{
color: #fff;
background-color: #337ab7;
margin-left: 70%;
padding: 7px;
}
Authenction.php
<?php include('connection.php'); $username = $_POST['user']; $password = $_POST['pass']; // To prevent SQL injection $username = stripslashes($username); $password = stripslashes($password); $username = mysqli_real_escape_string($con, $username); $password = mysqli_real_escape_string($con, $password); $sql = "SELECT * FROM login WHERE username = '$username' AND password = '$password'"; $result = mysqli_query($con, $sql); $count = mysqli_num_rows($result); if ($count == 1) { echo "<h1><center>Login successful</center></h1>"; } else { echo "<h1>Login failed. Invalid username or password.</h1>"; } ?>Connection.php
<?php $host = "localhost"; $user = "root"; $password = ''; $db_name = "studentdb"; $con = mysqli_connect($host, $user, $password, $db_name); if (mysqli_connect_errno()) { die("Failed to connect with MySQL: " . mysqli_connect_error()); } ?>