0% found this document useful (0 votes)
31 views11 pages

WT Slip Solutions

The document contains PHP code for multiple web pages that allow a user to enter employee details like number, name, address and earning details like basic pay, DA, HRA. The data is stored in sessions and passed between pages to display the complete employee information on the last page.

Uploaded by

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

WT Slip Solutions

The document contains PHP code for multiple web pages that allow a user to enter employee details like number, name, address and earning details like basic pay, DA, HRA. The data is stored in sessions and passed between pages to display the complete employee information on the last page.

Uploaded by

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

slip1.

php
<?php
// Start the session
session_start();

// Check if the session variable for page views exists


if(isset($_SESSION['page_views'])) {
$_SESSION['page_views']++; // Increment the page view count
} else {
$_SESSION['page_views'] = 1; // Set page view count to 1 if it doesn't exist
}

// Display the number of page views


echo "You have visited this page " . $_SESSION['page_views'] . " times.";

// To reset the page view count, you can uncomment the following line:
// unset($_SESSION['page_views']);
?>
-----------------------------------------------------------------------------------
-----------------
slip 4

earning_details.php

<?php
session_start();

// Check if the form is submitted


if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve earning details from the form
$basic = $_POST["basic"];
$da = $_POST["da"];
$hra = $_POST["hra"];

// Set session variables to store earning details


$_SESSION["earning_details"] = array(
'basic' => $basic,
'da' => $da,
'hra' => $hra
);

// Redirect to employee information page


header("Location: employee_info.php");
exit;
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Earning Details</title>
</head>
<body>
<h2>Enter Earning Details</h2>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"
method="post">
<label for="basic">Basic:</label>
<input type="text" name="basic" id="basic" required><br><br>
<label for="da">DA:</label>
<input type="text" name="da" id="da" required><br><br>
<label for="hra">HRA:</label>
<input type="text" name="hra" id="hra" required><br><br>
<input type="submit" value="Next">
</form>
</body>
</html>

employee_details.php

<?php
session_start();

// Check if the form is submitted


if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve employee details from the form
$eno = $_POST["eno"];
$ename = $_POST["ename"];
$address = $_POST["address"];

// Set session variables to store employee details


$_SESSION["employee_details"] = array(
'eno' => $eno,
'ename' => $ename,
'address' => $address
);

// Redirect to earning page


header("Location: earning_details.php");
exit;
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Employee Details</title>
</head>
<body>
<h2>Enter Employee Details</h2>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"
method="post">
<label for="eno">Employee Number:</label>
<input type="text" name="eno" id="eno" required><br><br>
<label for="ename">Employee Name:</label>
<input type="text" name="ename" id="ename" required><br><br>
<label for="address">Address:</label>
<input type="text" name="address" id="address" required><br><br>
<input type="submit" value="Next">
</form>
</body>
</html>

employee_info.php
<?php
session_start();

// Check if session variables are set


if (!isset($_SESSION["employee_details"]) || !isset($_SESSION["earning_details"]))
{
// Redirect to the first page if session variables are not set
header("Location: employee_details.php");
exit;
}

// Retrieve employee and earning details from session


$employee_details = $_SESSION["employee_details"];
$earning_details = $_SESSION["earning_details"];

// Calculate total earnings


$total = $earning_details['basic'] + $earning_details['da'] +
$earning_details['hra'];
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Employee Information</title>
</head>
<body>
<h2>Employee Information</h2>
<p><strong>Employee Number:</strong> <?php echo $employee_details['eno'];
?></p>
<p><strong>Employee Name:</strong> <?php echo $employee_details['ename'];
?></p>
<p><strong>Address:</strong> <?php echo $employee_details['address']; ?></p>
<p><strong>Basic:</strong> <?php echo $earning_details['basic']; ?></p>
<p><strong>DA:</strong> <?php echo $earning_details['da']; ?></p>
<p><strong>HRA:</strong> <?php echo $earning_details['hra']; ?></p>
<p><strong>Total Earnings:</strong> <?php echo $total; ?></p>
</body>
</html>
-----------------------------------------------------------------------------------
----------------------------------------
slip10.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Insert Text using jQuery</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
// Insert text before the paragraph
$("#addBefore").click(function(){
$("p").before("<b>text to added</b> ");
});

// Insert text after the paragraph


$("#addAfter").click(function(){
$("p").after(" <b>text to be added</b>");
});
});
</script>
</head>
<body>
<h2>Insert Text using jQuery</h2>
<p>This is a paragraph.</p>
<button id="addBefore">Add Text Before</button>
<button id="addAfter">Add Text After</button>
</body>
</html>
-----------------------------------------------------------------------------------
--------
slip16

filename:-books.xml

<books>
<book>
<title>Book 1</title>
<author>Author 1</author>
<year>2020</year>
<price>10.99</price>
</book>
<book>
<title>Book 2</title>
<author>Author 2</author>
<year>2019</year>
<price>15.99</price>
</book>
<book>
<title>Book 3</title>
<author>Author 3</author>
<year>2018</year>
<price>12.50</price>
</book>
</books>

filename:-get_books_details.php

<?php
$books = simplexml_load_file('books.xml');
$title = $_GET['title'];

foreach ($books->book as $book) {


if ($book->title == $title) {
echo "<h2>{$book->title}</h2>";
echo "<p>Author: {$book->author}</p>";
echo "<p>Year: {$book->year}</p>";
echo "<p>Price: {$book->price}</p>";
break;
}
}
?>

filename:-index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Book Details</title>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<label for="bookSelect">Select a Book:</label>
<select id="bookSelect">
<option value="">--Select a book--</option>
<option value="Book 1">Book 1</option>
<option value="Book 2">Book 2</option>
<option value="Book 3">Book 3</option>
</select>
<div id="bookDetails"></div>

<script>
$(document).ready(function () {
$('#bookSelect').change(function () {
var selectedBook = $(this).val();
$.ajax({
url: 'get_book_details.php',
method: 'GET',
data: {title: selectedBook},
success: function (response) {
$('#bookDetails').html(response);
}
});
});
});
</script>
</body>
</html>
-----------------------------------------------------------------------------------
-------------------
slip17.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Registration</title>
<script>
window.onload = function() {
alert("Hello! Good Morning");
};

function registerStudent() {
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;
var age = document.getElementById("age").value;

// You can perform validation here before submitting the form


// For simplicity, I'm just showing the entered values in an alert
alert("Name: " + name + "\nEmail: " + email + "\nAge: " + age);
// Here, you can submit the form to a server using AJAX or other
methods
// For demonstration purpose, I'm preventing the form from submitting
return false;
}
</script>
</head>
<body>
<h2>Student Registration Form</h2>
<form onsubmit="return registerStudent()">
<label for="name">Name:</label><br>
<input type="text" id="name" name="name"><br><br>

<label for="email">Email:</label><br>
<input type="email" id="email" name="email"><br><br>

<label for="age">Age:</label><br>
<input type="number" id="age" name="age"><br><br>

<input type="submit" value="Register">


</form>
</body>
</html>
-----------------------------------------------------------------------------------
----------------
slip18.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fibonacci Numbers</title>
</head>
<body>
<h2>Fibonacci Numbers</h2>
<button onclick="printFibonacci()">Print Fibonacci Numbers</button>
<div id="fibonacciList"></div>

<script>
function printFibonacci() {
var fibonacciList = document.getElementById("fibonacciList");
fibonacciList.innerHTML = ""; // Clear previous results

var n = parseInt(prompt("Enter the number of Fibonacci numbers you want


to generate:"));

if (isNaN(n) || n <= 0) {
alert("Please enter a valid positive number.");
return;
}

var fibSeries = [];


fibSeries[0] = 0;
fibSeries[1] = 1;

if (n >= 1) {
fibonacciList.innerHTML += fibSeries[0] + "<br>";
}

if (n >= 2) {
fibonacciList.innerHTML += fibSeries[1] + "<br>";
}

for (var i = 2; i < n; i++) {


fibSeries[i] = fibSeries[i - 1] + fibSeries[i - 2];
fibonacciList.innerHTML += fibSeries[i] + "<br>";
}
}
</script>
</body>
</html>

-----------------------------------------------------------------------------------
------------------
slip19.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Form</title>
</head>
<body>
<h2>Login Form</h2>
<form onsubmit="return validateForm()">
<label for="username">Username:</label><br>
<input type="text" id="username" name="username"><br><br>

<label for="password">Password:</label><br>
<input type="password" id="password" name="password"><br><br>

<input type="submit" value="Login">


</form>

<script>
function validateForm() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;

// Validation rules
if (username.trim() === "") {
alert("Please enter a username.");
return false;
}

if (password.trim() === "") {


alert("Please enter a password.");
return false;
}

// Additional validation rules can be added here as needed

// If all validations pass, return true to submit the form


return true;
}
</script>
</body>
</html>
-----------------------------------------------------------------------------------
------------------------------------------
slip20

filename:-students.xml

<?xml version="1.0" encoding="UTF-8"?>


<students>
<student>
<id>1</id>
<name>John Doe</name>
<grade>A</grade>
<age>20</age>
<city>New York</city>
</student>
<student>
<id>2</id>
<name>Jane Smith</name>
<grade>B</grade>
<age>22</age>
<city>Los Angeles</city>
</student>
<student>
<id>3</id>
<name>Michael Johnson</name>
<grade>A+</grade>
<age>21</age>
<city>Chicago</city>
</student>
<student>
<id>4</id>
<name>Emily Brown</name>
<grade>B-</grade>
<age>19</age>
<city>Houston</city>
</student>
<student>
<id>5</id>
<name>William Jones</name>
<grade>C+</grade>
<age>23</age>
<city>San Francisco</city>
</student>
</students>

filename:-view.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>View Students</title>
</head>
<body>
<h2>Student Information</h2>
<table border="1">
<tr>
<th>ID</th>
<th>Name</th>
<th>Grade</th>
<th>Age</th>
<th>City</th>
</tr>

<?php
// Load XML file
$xml = simplexml_load_file('students.xml');

// Loop through each student


foreach ($xml->student as $student) {
echo "<tr>";
echo "<td>" . $student->id . "</td>";
echo "<td>" . $student->name . "</td>";
echo "<td>" . $student->grade . "</td>";
echo "<td>" . $student->age . "</td>";
echo "<td>" . $student->city . "</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>
-----------------------------------------------------------------------------------
----------------------------------------
slip17

filename:-index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voter Registration</title>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h2>Voter Registration Form</h2>
<form id="voterForm" onsubmit="return validateForm()">
<label for="name">Name (Upper Case Letters Only):</label><br>
<input type="text" id="name" name="name"><br><br>

<label for="age">Age (Minimum 18 years):</label><br>


<input type="number" id="age" name="age"><br><br>

<label for="nationality">Nationality (Indian Only):</label><br>


<input type="text" id="nationality" name="nationality"><br><br>

<input type="submit" value="Submit">


</form>

<div id="message"></div>
<script>
function validateForm() {
var name = $('#name').val();
var age = $('#age').val();
var nationality = $('#nationality').val();

// Validation for name (uppercase letters only)


if (name !== name.toUpperCase()) {
$('#message').text("Name should be in uppercase letters only.");
return false;
}

// Validation for age (minimum 18 years)


if (age < 18) {
$('#message').text("Age should not be less than 18 years.");
return false;
}

// Validation for nationality (Indian only)


if (nationality.toLowerCase() !== 'indian') {
$('#message').text("Nationality should be Indian only.");
return false;
}

// If all validations pass, return true to submit the form


return true;
}
</script>
</body>
</html>

filename:-submit.php

<?php
$name = $_POST['name'];
$age = $_POST['age'];
$nationality = $_POST['nationality'];

// Perform any server-side validation if required

// Process the form submission (e.g., save to database)


// For demonstration purposes, just echoing the received data
echo "Name: $name<br>";
echo "Age: $age<br>";
echo "Nationality: $nationality<br>";
?>
-----------------------------------------------------------------------------------
-----------------------------------------
slip29.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Number Operations</title>
</head>
<body>
<h2>Number Operations</h2>
<form method="post" action="<?php echo
htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
Enter a number: <input type="text" name="number">
<input type="submit" name="submit" value="Submit">
</form>

<?php
// Function to generate Fibonacci series
function fibonacci($n) {
$fib = [];
$fib[0] = 0;
$fib[1] = 1;
for ($i = 2; $i < $n; $i++) {
$fib[$i] = $fib[$i - 1] + $fib[$i - 2];
}
return $fib;
}

// Function to calculate sum of digits


function sumOfDigits($number) {
$sum = 0;
while ($number > 0) {
$digit = $number % 10;
$sum += $digit;
$number = (int)($number / 10);
}
return $sum;
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$number = $_POST["number"];
if (is_numeric($number)) {
echo "<h3>Results:</h3>";
echo "Input Number: $number <br>";

// Fibonacci series
echo "<h4>Fibonacci Series:</h4>";
$fibSeries = fibonacci($number);
echo implode(", ", $fibSeries) . "<br>";

// Sum of digits
echo "<h4>Sum of Digits:</h4>";
echo "Sum: " . sumOfDigits($number);
} else {
echo "<p style='color: red;'>Please enter a valid number.</p>";
}
}
?>
</body>
</html>
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------

You might also like