In this tutorial we are writing a PHP Program to Check Eligibility for voting.
To check that a person is eligible for voting or not, we need to check whether person’s age is greater than or equal to 18. For this we are reading age in a variable a and checking the condition a>=18, if the condition is true, “person will be eligible for voting” else not.
Program Source Code : PHP program to check eligibility for voting
PHP Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<html> <head> <title>PHP Test</title> </head> <body> <form method="get"> <input name="age" placeholder="enter age"><br> <input name="btn" type="submit" value="Submit Age"> <?php if(isset($_GET["age"])) { //solution $age = $_GET["age"]; echo "<h2> Your Age:$age<h2>"; if ($age >= 18) echo "<h1>Eligible for Voting!</h1>"; else echo "<h1>Not Eligible for Voting!</h1>"; } ?> </form> </body> </html> |
Output:
