PHP Program To Find The Leap year with form and database
PHP Program To Find The Leap year with form and database
In this tutorial, we will learn about the followings.
- PHP Program To Find The Leap year.
- PHP Program To Find The Leap year with a form.
- PHP Program To Find The Leap year with the database.
PHP Program To Find The Leap year.
In this example, we will take the inputs from the user and store them in variables.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php $value; $value = 2012; echo "Enter a year <br>"; echo "$value <br>"; if($value % 4 == 0) { echo "$value is a leap year"; } else { echo "$value is Not a leap year"; } ?> |
PHP Program To Find The Leap year with a form.
In this example, programmer stores the values in the variables. However, if you interested to see the program about taking values in the form, please see example 2.
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 27 28 29 30 |
<html> <head></head> <body> <form method="post"> Enter a year:<input type = "text" name="year" /><br> <input type="submit" id="btnsubmit" name="btnsubmit" value="submit" style ="align:center;margin-left: 135px;margin-top: 5px;"/> </form> </body> </html> <?php /*include 'db1.php';*/ if(isset($_POST['btnsubmit'])) { $value = 0; $value = $_POST['year']; // echo $value; if($value % 4 == 0) { echo $value. " is a leap year"; } else { echo $value. " is Not a leap year"; } } ?> |
PHP Program To Find The Leap year with the database.
In this example, we will take the inputs from the user and temporarily store them in variables and then finally stores them permanently in the database.
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<html> <head></head> <body> <
form method="post"> Enter a year:<input type = "text" name="year" /><br> <input type="submit" id="btnsubmit" name="btnsubmit" value="Year" style ="align:center;margin-left: 135px;margin-top: 5px;"/> </form> </body> </html> <?php include 'database.php'; if(isset($_POST['btnsubmit'])) { $value=$_POST['year']; $temp=$value; // echo $value; if($value % 4 == 0) { echo "$value is a leap year"; $v1=" is a leap year"; } else { echo "$value is Not a leap year"; $v1=" is Not a leap year"; } $sql="INSERT INTO leapyear (Years,Result) VALUES ('$temp','$v1') "; if(mysqli_query($conn,$sql)) { // echo "record successfully"; } } ?> |
database.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php $servername="localhost"; $username="root"; $password=""; $dbname="LeapYear"; //create a connection $conn= new mysqli($servername,$username,$password,$dbname); //check connection if($conn->connect_error) { die ("connection failed:" . $conn->connect_error); } //connected successfully else { //echo "connected successfully."; } ?> |
Database of Program To Find The Leap year with the database.