0% found this document useful (0 votes)
1 views

PHP_Lab_Tasks_Solution

The document contains three HTML tasks: a multiplication table generator that displays the multiplication results for a user-input number, an even or odd checker that determines if a user-input number is even or odd, and a username and password validation form that grants access if the correct credentials are entered. Each task includes PHP code to handle form submissions and display results. Sample outputs for each task are provided to illustrate expected results.

Uploaded by

Kashaf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

PHP_Lab_Tasks_Solution

The document contains three HTML tasks: a multiplication table generator that displays the multiplication results for a user-input number, an even or odd checker that determines if a user-input number is even or odd, and a username and password validation form that grants access if the correct credentials are entered. Each task includes PHP code to handle form submissions and display results. Sample outputs for each task are provided to illustrate expected results.

Uploaded by

Kashaf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Task 1: Multiplication Table Generator

<!DOCTYPE html>

<html>

<head><title>Multiplication Table</title></head>

<body>

<form method="post">

Enter a number: <input type="number" name="num">

<input type="submit" value="Generate Table">

</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$num = $_POST['num'];

echo "<h3>Multiplication Table for $num</h3>";

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

echo "$num x $i = " . ($num * $i) . "<br>";

?>

</body>

</html>

Sample Output:

Multiplication Table for 5

5x1=5
5 x 2 = 10

5 x 3 = 15

5 x 4 = 20

5 x 5 = 25

5 x 6 = 30

5 x 7 = 35

5 x 8 = 40

5 x 9 = 45

5 x 10 = 50
Task 2: Even or Odd Checker

<!DOCTYPE html>

<html>

<head><title>Even or Odd Checker</title></head>

<body>

<form method="post">

Enter a number: <input type="number" name="num">

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

</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$num = $_POST['num'];

if ($num % 2 == 0) {

echo "$num is Even.";

} else {

echo "$num is Odd.";

?>

</body>

</html>

Sample Output:

5 is Odd.
Task 3: Username and Password Validation

<!DOCTYPE html>

<html>

<head><title>Login Validation</title></head>

<body>

<form method="post">

Username: <input type="text" name="username"><br>

Password: <input type="password" name="password"><br>

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

</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$username = $_POST['username'];

$password = $_POST['password'];

if ($username == "Your Roll No" && $password == "21BBA") {

echo "Welcome, $username!";

} else {

echo "Error: Invalid username or password.";

?>

</body>

</html>
Sample Output:

Welcome, Your Roll No!

You might also like