Practical Viewer

Practical Programs

IT Practical Solution

1 Programs Found
1 Program 1
Aim (Write on the ruler page)
Write a PHP program to check if a person is eligible to vote or not. The program should include the following- ➤ Minimum age required for vote is 18. ➤ Use PHP functions. ➤ Use Decision making statement.
Program (Start from new page after AIM)
<!DOCTYPE html>
<html>
<head>
<title>Eligible to Vote or not</title>
</head>
<body>
<form action="" method="post">
Enter Your Age :
<input type="text" name="t1" placeholder="Enter a
number">
<br><input type="submit" name="submit"
value="submit">
</form>
<?php
if (isset($_POST['submit'])) {
vote();
}
function vote() {
$a = $_POST['t1'];
intval($a);
if($a>=18){
echo "You are Eligible for Vote";
}
else{
echo "You are not Eligible for Vote";
}
}
?>
</body>
</html>
Output (Stick on blank page opposite to code)
Download Output