Professional Documents
Culture Documents
WP 20 PRGM
WP 20 PRGM
<!DOCTYPE html>
<html>
<head>
<title>Form Validation</title>
<script>
function validateForm() {
const email = document.getElementById('email').value;
const mobile = document.getElementById('mobile').value;
const textbox = document.getElementById('textbox').value;
let errorMessage = "";
Program 02
<!DOCTYPE html>
<html>
<head>
<title>Math Expression Evaluator</title>
<script>
function evaluateExpression() {
const expression = document.getElementById('expression').value;
try {
const result = eval(expression);
document.getElementById('result').textContent = `Result: ${result}`;
} catch (error) {
document.getElementById('result').textContent = "Invalid expression or operation.";
}
}
</script>
</head>
<body>
<h2>Math Expression Evaluator</h2>
<form>
Enter a mathematical expression:
<input type="text" id="expression">
<input type="button" value="Evaluate" onclick="evaluateExpression()">
</form>
<p id="result"></p>
</body>
</html>
Program 03
<!DOCTYPE html>
<html>
<head>
<title>Dynamic Effects with Layers and Basic Animation</title>
<style>
.layer {
position: absolute;
width: 100px;
height: 100px;
background-color: #3498db;
border-radius: 50%;
transition: all 0.5s ease-in-out;
}
</style>
</head>
<body>
<script>
function moveLayers() {
const layer1 = document.getElementById('layer1');
const layer2 = document.getElementById('layer2');
const layer3 = document.getElementById('layer3');
</body>
</html>
Program 04
<!DOCTYPE html>
<html>
<head>
<title>Sum of N Natural Numbers</title>
<script>
function sumOfNaturalNumbers(n) {
let sum = 0;
for (let i = 1; i <= n; i++) {
sum += i;
}
return sum; // Return sum after the loop completes
}
function calculateSum() {
const N = parseInt(document.getElementById('number').value);
if (!isNaN(N) && N > 0) {
const sum = sumOfNaturalNumbers(N);
document.getElementById('result').textContent = `The sum of first ${N} natural numbers is:
${sum}`;
} else {
document.getElementById('result').textContent = "Please enter a valid positive integer.";
}
}
</script>
</head>
<body>
<h2>Sum of N Natural Numbers</h2>
Enter a positive integer (N): <input type="text" id="number">
<button onclick="calculateSum()">Calculate</button>
<p id="result"></p>
</body>
</html>
Program 05
<!DOCTYPE html>
<html>
<head>
<title>Current Date in Words</title>
</head>
<body>
<script>
const daysOfWeek = [
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
];
const monthsOfYear = [
"January", "February", "March", "April", "May", "June", "July", "August", "September",
"October", "November", "December"
];
</body>
</html>
Program 06
<!DOCTYPE html>
<html>
<head>
<title>Student Information Form</title>
<script>
function calculateResult() {
var math = parseFloat(document.getElementById('math').value);
var science = parseFloat(document.getElementById('science').value);
var english = parseFloat(document.getElementById('english').value);
var result = (math >= 35 && science >= 35 && english >= 35) ? "Pass" : "Fail";
var grade;
if (average >= 90) {
grade = 'A+';
} else if (average >= 80) {
grade = 'A';
} else if (average >= 70) {
grade = 'B';
} else if (average >= 60) {
grade = 'C';
} else if (average >= 50) {
grade = 'D';
} else {
grade = 'F';
}
document.getElementById('totalMarks').value = totalMarks.toFixed(2);
document.getElementById('average').value = average.toFixed(2);
document.getElementById('result').value = result;
document.getElementById('grade').value = grade;
}
</script>
</head>
<body>
<h2>Student Information</h2>
<form>
Math: <input type="number" id="math"><br><br>
Science: <input type="number" id="science"><br><br>
English: <input type="number" id="english"><br><br>
<input type="button" value="Calculate" onclick="calculateResult()">
</form>
<br>
<h2>Result Details</h2>
Total Marks: <input type="text" id="totalMarks" readonly><br><br>
Average: <input type="text" id="average" readonly><br><br>
Result: <input type="text" id="result" readonly><br><br>
Grade: <input type="text" id="grade" readonly>
</body>
</html>
Program 07
<!DOCTYPE html>
<html>
<head>
<title>Employee Information Form</title>
<script>
function calculateSalary() {
var basicSalary = parseFloat(document.getElementById('basicSalary').value);
var allowance = parseFloat(document.getElementById('allowance').value);
var taxRate = parseFloat(document.getElementById('taxRate').value);
document.getElementById('DA').value = DA.toFixed(2);
document.getElementById('HRA').value = HRA.toFixed(2);
document.getElementById('PF').value = PF.toFixed(2);
document.getElementById('grossPay').value = grossPay.toFixed(2);
document.getElementById('deduction').value = deduction.toFixed(2);
document.getElementById('netPay').value = netPay.toFixed(2);
}
</script>
</head>
<body>
<h2>Employee Information</h2>
<form>
Basic Salary: <input type="number" id="basicSalary"><br><br>
Allowance: <input type="number" id="allowance"><br><br>
Tax Rate(%): <input type="number" id="taxRate"><br><br>
<input type="button" value="Calculate" onclick="calculateSalary()">
</form><br>
<h2>Salary Details</h2>
</body>
</html>
Program 08
<?php
<!DOCTYPE html>
<html>
<head>
<title>Background Color Based on Day of the Week</title>
<style>
body {
background-color: <?php echo $backgroundColor; ?>;
}
</style>
</head>
<body>
<h1>Welcome! Today is <?php echo $currentDay; ?></h1>
</body>
</html>
Program 09
<?php
function isPrime($num) {
if ($num <= 1) {
return false;
}
return true;
}
function generatePrimes($n) {
$primeNumbers = [];
$count = 0;
$i = 2;
return $primeNumbers;
}
function generateFibonacci($n) {
$fibonacciSeries = [];
$first = 0;
$second = 1;
$fibonacciSeries[] = $first;
$fibonacciSeries[] = $second;
return $fibonacciSeries;
}
$numberOfPrimes = 10;
$numberOfTerms = 10;
$primes = generatePrimes($numberOfPrimes);
$fibonacci = generateFibonacci($numberOfTerms);
<?php
function removeDuplicates($array) {
$result = array_values(array_unique($array));
return $result;
}
$uniqueList = removeDuplicates($sortedList);
?>
Program 11
<?php
// Printing asterisks
for ($k = 0; $k < $i; $k++) {
echo "*";
}
?>
Program 12
<?php
$data = [
['id' => 1, 'name' => 'Srikanth', 'age' => 30],
['id' => 2, 'name' => 'Srinath', 'age' => 35],
['id' => 3, 'name' => 'Srinivas', 'age' => 50],
['id' => 4, 'name' => 'Smayan', 'age' => 45],
['id' => 5, 'name' => 'Saatvik', 'age' => 50],
];
if (!is_array($data) || !is_array($criteria)) {
throw new InvalidArgumentException('Invalid data or criteria format (expected arrays)');
}
if (!is_array($entry)) {
continue;
}
if ($match) {
$results[] = $entry;
}
}
return $results;
}
$criteria = ['age' => 50];
try {
?>
Program 13
<?php
session_start();
function generateCaptchaCode($length = 6) {
$characters =
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ;';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
?>
Program 14
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</form>
<h2>Uploaded Images:</h2>
<?php
// Connect to the database
$conn = new mysqli("localhost", "root", "", "myDB"); // Update with your credentials
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
</body>
</html>
Program 15
<!DOCTYPE html>
<html>
<head>
<title>File Reader and Writer</title>
</head>
<body>
</body>
</html>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
try {
if (!empty($_POST['userText'])) {
file_put_contents("output.txt", htmlspecialchars($_POST['userText']));
echo "Data written to file.";
}
if (!empty($_FILES['filedata']['tmp_name'])) {
$fileContent = file_get_contents($_FILES['filedata']['tmp_name']);
echo "File content: " . htmlspecialchars($fileContent) . "<br>";
}
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
}
?>
Program 16
<?php
// Database connection details (replace with your actual credentials)
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($result->num_rows > 0) {
echo "<table border='1'><tr><th>Reg
No</th><th>Name</th><th>Age</th><th>Course</th></tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr><td>" . htmlspecialchars($row["regno"]) . "</td><td>" .
htmlspecialchars($row["name"]) . "</td><td>" . $row["age"] . "</td><td>" .
htmlspecialchars($row["course"]) . "</td></tr>";
}
echo "</table>";
} else {
echo "No students found.";
}
$stmt = null;
switch ($action) {
case 'add':
$sql = "INSERT INTO student (regno, name, age, course) VALUES (?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param('ssss', $regno, $name, $age, $course);
break;
case 'update':
$sql = "UPDATE student SET name = ?, age = ?, course = ? WHERE regno = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param('sssi', $name, $age, $course, $regno);
break;
case 'delete':
$sql = "DELETE FROM student WHERE regno = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param('s', $regno);
break;
}
if ($stmt) {
$stmt->execute();
$stmt->close(); // Close the prepared statement (best practice)
if ($conn->affected_rows > 0) {
echo "Operation successful.";
} else {
echo "No records affected.";
}
} else {
echo "Error: " . $conn->error;
}
}
// Close connection
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>Student Database Management</title>
</head>
<body>
<h1>Manage Students</h1>
<form method="post">
Reg No: <input type="text" name="regno" required><br><br>
Name: <input type="text" name="name"><br><br>
Age: <input type="number" name="age"><br><br>
Course: <input type="text" name="course"><br><br>
<input type="submit" name="action" value="Add">
<input type="submit" name="action" value="Update">
<input type="submit" name="action" value="Delete">
</form>
</body>
</html>
Program 17
<!DOCTYPE html>
<html>
<head>
<title>Input Validation</title>
</head>
<body>
<form method="post">
</form>
</body>
</html>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$email = $_POST['email'];
if (empty($name)) {
} else {
if (empty($email)) {
} else {
?>
Program 18
<!DOCTYPE html>
<html>
<head>
<title>Cookie Handler</title>
</head>
<body>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Set the cookie with a name and value from the form
echo "<p>Cookie set. Reload the page to see the cookie value.</p>";
}
// Check if the cookie named "username" exists
if(isset($_COOKIE["username"])) {
} else {
?>
</form>
</body>
</html>
Program 19
Index.php
<!DOCTYPE html>
<html>
<head>
<style>
body {
header {
background-color: #f8f9fa;
padding: 20px;
text-align: center;
nav {
margin: 20px 0;
text-align: center;
}
nav a (
margin: 0 15px;
}
</style>
</head>
<body>
<header>
</header>
<nav>
<a href="index.php">Home</a>
<a href="courses.php">Courses</a>
</nav>
<main>
</main>
</body>
</html>
About.php
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>About Us</h1>
<p>Skyward Institute of Computer Applications was founded in 2010 with the aim to provide
quality education in the field of computer applications...</p>
</body>
</html>
Courses.php
<!DOCTYPE html>
<html>
<head>
<title>Courses
</head>
<body>
<h1>Courses</h1>
<h2>BCA</h2>
<h2>MCA</h2>
</body>
</html>
Contact.php
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Contact Us</h1>
<p>Phone: +91-9611185999</p>
<p>Email: skyward.publishers@gmail.com</p>
</body>
</html>
Program 20
<?php
try {
echo divide(10, 2) . "<br>";
echo divide(10, 0) . "<br>";
} catch (Exception $e) {
echo "Division error: " . $e->getMessage() . "<br>";
}
try {
checkDateFormat("2023-03-10");
checkDateFormat("10/03/2023");
} catch (Exception $e) {
echo "Date error: " . $e->getMessage() . "<br>";
}
?>