0% found this document useful (0 votes)
20 views15 pages

Wplab - PDF 20231229 145152 0000

Uploaded by

Sanathan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views15 pages

Wplab - PDF 20231229 145152 0000

Uploaded by

Sanathan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

MLRInstitute of Technology

Laxma Reddy Avenue, Dundigal, Quthbullapur (M), Hyderabad – 500 043


Phone Nos: 08418 – 204066 / 204088, Fax : 08418 – 204088

WEB PROGRAMMING-LAB
Student Name P SANATHAN
Roll No:21R21A66DH7
Branch: CSM-C Year & Semester:III/I
Academic Year:2022-23 Week No:7

1) PROBLEM STATEMENT:
Write an HTML page including required PHP code that contains a selection box
with a list of 5 countries. When the user selects a country, its capital should be
printed next to the list. Add CSS to customize the properties of the font of the
capital (color, bold and font size).
Source code:

<!DOCTYPE html>
<html>
<head>
<title>Country Capitals</title>
<style>
.capital {
color: red;
font-weight: bold;
font-size: 18px;
}
</style>
</head>
<body>
<h1>Select a Country:</h1>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="country" onchange="this.form.submit()">
<option value="">Select a Country</option>
<option value="usa">USA</option>
<option value="uk">UK</option>
<option value="france">France</option>
<option value="germany">Germany</option>
<option value="japan">Japan</option>
</select>
</form>
<?php
$capitals = [
'usa' => 'Washington
D.C.', 'uk' => 'London',
'france' => 'Paris',
'germany' => 'Berlin',
'japan' => 'Tokyo'
];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$selectedCountry = $_POST['country'];
if (array_key_exists($selectedCountry, $capitals)) {
$capital = $capitals[$selectedCountry];
echo "<p>The capital of <strong>" . ucfirst($selectedCountry) . "</strong> is: <span
class='capital'>" . $capital . "</span></p>";
} else {
echo "<p>No capital found for the selected country.</p>";
}
}
?>
</body>
</html>

output:

2) PROBLEM STATEMENT:
Write a PHP program to check whether the number is even or odd
SOURCE CODE:
<?php
function checkEvenOdd($number) {
if ($number % 2 == 0) {
echo $number . " is even.";
} else {
echo $number . " is odd.";
}
}

// Test the function with a number


$testNumber = 15;
checkEvenOdd($testNumber);
?>
OUTPUT:

3) PROBLEM STATEMENT:
Write a PHP program to check whether the number is positive, negative or zero.
SOURCE CODE:
<?php
function checkNumber($number) {
if ($number > 0) {
echo $number . " is positive.";
} elseif ($number < 0) {
echo $number . " is negative.";
} else {
echo $number . " is zero.";
}
}

// Test the function with a number


$testNumber = -7;
checkNumber($testNumber);
?>
OUTPUT:

4) PROBLEM STATEMENT:
Write a PHP program to find factorial of a number.
SOURCE CODE:
<?php
function calculateFactorial($number) {
if ($number < 0) {
echo "Factorial is not defined for negative numbers.";
} elseif ($number == 0 || $number == 1) {
echo "The factorial of " . $number . " is 1.";
} else {
$factorial = 1;
for ($i = 2; $i <= $number; $i++) {
$factorial *= $i;
}
echo "The factorial of " . $number . " is " . $factorial . ".";
}
}

// Test the function with a number


$testNumber = 5;
calculateFactorial($testNumber);
?>
OUTPUT:

5) PROBLEM STATEMENT:
Write a PHP program to find square of a number.
SOURCE CODE:
<?php
function calculateSquare($number) {
$square = $number * $number;
echo "The square of " . $number . " is " . $square . ".";
}

// Test the function with a number


$testNumber = 7;
calculateSquare($testNumber);
?>
OUTPUT:

6) PROBLEM STATEMENT:
Write a PHP program to find the factors of a
SOURCE CODE:
number. <?php
function findFactors($number) {
echo "The factors of " . $number . " are: ";

for ($i = 1; $i <= $number; $i++) {


if ($number % $i == 0) {
echo $i . " ";
}
}
}
// Test the function with a number
$testNumber = 12;
findFactors($testNumber);
?>
OUTPUT:
MLR Institute of Technology

Laxma Reddy Avenue, Dundigal, Quthbullapur (M), Hyderabad – 500 043 Phone Nos:
08418 – 204066 / 204088, Fax : 08418 – 204088

WEB PROGRAMMING-LAB
Student Name: P SANATHAN
Roll No:21R21A66H7
Branch: CSM-C Year & Semester:III/I
Academic Year:2022-23
Week No:08

A) PROBLEM STATEMENT: Write an HTML page including any required PHP that takes a number from one text field in the
range of 0 to 999 and shows it in range of 0 to 999 and shows it in another text field in words. If the number is out of range, it
should show “out of range” and if it is not a number, it should show “not a number” message in the result box.
Source code:
<html>
<head>
<title>Number to Words Converter</title>
<script>
function convertNumberToWords() {
var numberInput = document.getElementById("numberInput").value;
var resultBox = document.getElementById("resultBox");

// Check if the input is a valid number within the range


if (isNaN(numberInput)) {
resultBox.value = "Not a number";
} else if (numberInput < 0 || numberInput > 999) {
resultBox.value = "Out of range";
} else {
var words = convertToWords(numberInput);
resultBox.value = words;
}
}

function convertToWords(number) {
var units = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
var tens = ['', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];
var teens = ['', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'];

var words = '';

if (number == 0) {
words = 'zero';
} else if (number < 10) {
words = units[number];
} else if (number < 20) {
words = teens[number - 10];
} else if (number < 100) {
words = tens[Math.floor(number / 10)] + ' ' + units[number % 10];
} else {
words = units[Math.floor(number / 100)] + ' hundred ' + convertToWords(number % 100);
}

return words.trim();
}
</script>
</head>
<body>
<h2>Number to Words Converter</h2>
<label for="numberInput">Enter a number (0-999):</label>
<input type="text" id="numberInput" name="numberInput" required><br><br>

<button onclick="convertNumberToWords()">Convert</button><br><br>

<label for="resultBox">Result:</label>
<input type="text" id="resultBox" name="resultBox" readonly>
</body>
</html

output:

1)problem statement : Write a PHP program to check whether the number is prime or not
<?php
Program:
function primeCheck($number){
if ($number == 1)
return 0;
for ($i = 2; $i <= $number/2; $i++){
if ($number % $i == 0)
return 0;
}
return 1;
}
$number = 31;
$flag = primeCheck($number);
if ($flag == 1)
echo "Prime";
else
echo "Not Prime"
?>

Output:

2)problem statement
: Write a PHP program to find sum of array elements.
Program:
<?php
$array = [1, 2, 3, 4, 5];
$sum = array_sum($array);
echo "Sum of array elements: " . $sum;
?>
Output:

3)problem : Write a PHP program to find minimum element in the array.


statement
Program:
<?php
$array = [5, 3, 8, 2, 7];
$min = min($array);
echo "Minimum element in the array: " . $min;
?>
Output:
)4problem statement
: Write a PHP program to find absolute value of a given number.
Program:
<?php
$number = -10;
$absoluteValue = abs($number);
echo "Absolute value of " . $number . " is " . $absoluteValue;
?>
Output:
MLR Institute of Technology
Laxma Reddy Avenue, Dundigal, Quthbullapur (M), Hyderabad – 500 043
Phone Nos: 08418 – 204066 / 204088, Fax : 08418 – 20408

WEB PROGRAMMING-LAB
Student Name:P SANATHAN Roll No:21R21A66H7
Branch: CSM-C Year & Semester:III/I
Academic Year:2022-23 Week No:10

1) PROBLEM STATEMENT:Create a div using jQuery with style tag


Source code:
<!DOCTYPE html>
<html>
<head>
<style>
.myDiv {
border: 5px outset red;
background-color: lightblue;
text-align: center;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".myDiv").click(function(){
$(".abc").toggle();
});
});
</script>
</head>
<body>
<h1 class="abc">The div element</h1>

<div class="myDiv">
<h2 class ="abc">This is a heading in a div element</h2>
<p>This is some text in a div element.</p>
</div>
<p>This is some text outside the div element.</p>

</body>
</html>
output:
PROBLEM STATEMENT:Write a jQuery program for element selector.
Source code:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>element demo</title>
<style>
div, span {
width: 60px;
height: 60px;
float: left;
padding: 10px;
margin: 10px;
background-color: #eee;
}
</style>
<script src="https://code.jquery.com/jquery-3.7.0.js"></script>
</head>
<body>

<div>DIV1</div>
<div>DIV2</div>
<span>SPAN</span>

<script>
$( "div" ).css( "border", "9px solid red" );
</script>

</body>
</html>
OUTPUT:
MLR Institute of Technology
Laxma Reddy Avenue, Dundigal, Quthbullapur (M), Hyderabad – 500 043
Phone Nos: 08418 – 204066 / 204088, Fax : 08418 – 204088
WEBPROGRAMMING-LAB
Student Name: P SANATHAN
Roll No:21R21A66H7
Branch: CSM-C Year & Semester:III/I
Academic Year:2022-23 Week No:09

Problem tatement
S:Implement the following web applications using PHP:A user validation web
application, where the user submits the login name and password to the server. The name and
password are checked against the data already available in Database and if the data matches, a
successful login page is returned. Otherwise a failure message is shown to the user.
AIM: A user validation application using PHP and database.
Source
: code
Week-9.html:
<html>
<form action="week9.php" method="post">
Email:<input type="text" name="email">
<br>
Password:<input type="password" name="pwd">
<input type="submit" name="submit">
</form>
</html>
Week9.php:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mylogin";
$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$email = $_POST["email"];
$pwd = $_POST["pwd"];
$sql = "SELECT * FROM registration WHERE email='$email' AND password='$pwd'";
$result = $conn->query($sql);
if ($result !== false && $result->num_rows > 0) {
echo "Login successful";
} else {
echo "Login failed";
}
$conn->close();
}
?>
Output:

1.Problem Statement : Write a PHP program to demonstrate sessions.


Source code :
Php code:
<?php
// Start the session
session_start();
// Check if a session variable named 'counter' exists, if not, initialize it
if (!isset($_SESSION['counter'])) {
$_SESSION['counter'] = 0;
} else {
// Increment the counter if the session variable exists
$_SESSION['counter']++;
}
?>
Html code:
<!DOCTYPE html>
<html>
<head>
<title>Session Example</title>
</head>
<body>
<h1>Session Example</h1>
<p>Refresh this page to increase the counter:</p>
<p>
Counter: <?php echo $_SESSION['counter']; ?>
</p>
</body>
</html>
Output :

2.Problem
Write statement:
a PHP program to demonstrate cookies.
Source code :
<?php
// Set a cookie with name "user" and value "John Doe" that expires in 1 hour (3600 seconds)
$cookie_name = "user";
$cookie_value = "John Doe";
$cookie_expiry = time() + 3600; // Current time + 1 hour
setcookie($cookie_name, $cookie_value, $cookie_expiry, "/");
// Check if the cookie is set and display its value
if (!isset($_COOKIE[$cookie_name])) {
echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
echo "Cookie '" . $cookie_name . "' is set!<br>";
echo "Value: " . $_COOKIE[$cookie_name];
}

// Delete the cookie - uncomment the line below to delete the cookie
// setcookie($cookie_name, "", time() - 3600, "/"); // Expire the cookie by setting a past time
?>

Output :
MLR Institute of Technology
Laxma Reddy Avenue, Dundigal, Quthbullapur (M), Hyderabad – 500 043
Phone Nos: 08418 – 204066 / 204088, Fax : 08418 – 204088

WEB PROGRAMMING-LAB
NAME: P SANATHAN
Roll No:21R21A66H7
Branch: CSM-C Year & Semester:III/I
Academic Year:2022-23 Week No:11
1) PROBLEM STATEMENT: Create a Zebra Stripes table effect using
jQuery Source code:
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border: 1px solid;
}
th, td {
text-align: left;
padding: 16px;
}
tr:nth-child(even) {
background-color: yellow;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".tab").hide();
$("#t").click(function(){
$("#t1").show();
});
$("#t1").click(function(){
$("#t2").show();
});
$("#t2").click(function(){
$("#t3").show();
});
});
</script>
</head>
<body>
<h2>Zebra Striped Table</h2>
<p>For zebra-striped tables, use the nth-child() selector and add a background-color to all even (or odd)
table rows:</p>
<table>
<tr id="t">
<th>First Name</th>
<th>Last Name</th>
<th>Points</th>
</tr>
<tr id="t1" class="tab">
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr id="t2" class="tab">
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr id="t3" class="tab">
<td>Adam</td>
<td>Johnson</td>
<td>67</td>
</tr>
</table>
</body>
</html>
output:

1) PROBLEM STATEMENT: Write a jQuery program for element selector.


Source code:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
// Hide button click handler
$("#hideButton").click(function(){
$("#myElement").hide();
});
// Show button click handler
$("#showButton").click(function(){
$("#myElement").show();
});
});
</script>
</head>
<body>
<p id="myElement">This is the element to hide or show.</p>

<button id="hideButton">Hide</button>
<button id="showButton">Show</button>
</body>
</html>

output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy