John Davidson

html - Using the isset function in php I want to display a confirmation message but its not showing properly


Basically I created a leapyear calculator, but to improve user experience i want it to display a message on the webpage confirming whether or not the year entered is a leapyear without changing the webpage.

<html lang="en">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Web,programming" />
<title>Leap year form</title>
$year = isset($_GET["leapyear"]);
function is_leapyear($year){

if($year%4 ==0)
if($year%100 ==0)
if($year%400 ==0){
return true;
return false;
if (isset($_GET["confirm"])){
if ($year == true){
echo'<span style="color:#008631;">';
echo"$year is a leap year</span>";
echo'<span style="color:#FF0000;">';
echo "$year is not a leap year</span>";
<h1>Lab 03 Task 2 - Leap Year</h1>
<form action = "leapyear_selfcall.php" method = "get" >
<label for="leapyear">Enter a year</label>
<input type="text" name="leapyear"/>
<input type="submit" name="confirm" value="Check For Leap Year"/>

The result I get is "1 is a leapyear" and not the entered input. Where did I make the mistake?

My Answer:
To display a confirmation message using the isset function in PHP, you can follow these steps:

1. First, make sure you have a form on your webpage where users can enter a year to check if it is a leap year. For example:


2. Next, in your PHP code, check if the form has been submitted and if the 'year' input field is set. If it is set, calculate if the year is a leap year and display a confirmation message. Here's an example:

if(isset($_POST['year'])) {
$year = $_POST['year'];

if((($year % 4 == 0) && ($year % 100 != 0)) || ($year % 400 == 0)) {
$message = "The year $year is a leap year.";
} else {
$message = "The year $year is not a leap year.";

Leap Year Calculator

Leap Year Calculator

With this code, when a user enters a year and submits the form, the PHP code will check if the year is a leap year and display a confirmation message on the webpage without changing the layout.

Rate this post

3 of 5 based on 1560 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us