How to Create Even and Odd Numbers Calculator in PHP?

Experts php tutorial has come up with a new topic. That how you will make calculator to get odd and even number through php program. So let’s go guys, you must have printed odd and even number on your local server through php program. You will be told today how the calculator to print odd number is made by php program.

Topic

  1. Create HTML code.
  2. Creat php code of odd and even number print.
  3. Mix html/PHP Code in One File (odd-even-numbers-calculator.php).

Create HTML code.

To get odd and even number through calcutor, you have to first create the form in an html. So first of all you create the form in html. In the form, you have to take an input type of text. And then a submit button. You are given the code of the form with the example below. With the help of which you can understand.

<html>
<head>
<meta charset="utf-8">
<title>Odd/Even Numbers Checker Calculator</title>
</head>
<body>
<form method="post">
<p>Input Your Number:<br/>
<input type="text" name="num"></p>
<input type="submit" name="submit" value="Check Odd/Even Numbers">
</form>
</body>
</html>

Creat php code of odd and even number print.

Now you have been told about the most important code below. You can get odd and even number with the help of this code. Now you can understand this code by looking below.

<?php 
if (isset($_POST['submit'])) {
$value = $_POST['num'];
if ($value % 2) {
echo '"'.$value.'" is odd';
} else {
echo '"'.$value.'" is even';
}
}
?>

Mix html/PHP Code in One File (odd-even-numbers-calculator.php).

Now you have to add this code to a single file (odd-even-numbers-calculator.php). The example of which is given below. You can copy the code of this file to your php You can use it by adding it to the file.

odd-even-numbers-calculator.php

<html>
<head>
<meta charset="utf-8">
<title>Odd/Even Numbers Checker Calculator</title>
</head>
<body>
<form method="post">
<p>Input Your Number:<br/>
<input type="text" name="num"></p>
<input type="submit" name="submit" value="Check Odd/Even Numbers">
</form>
</body>
</html>
<?php 
if (isset($_POST['submit'])) {
$value = $_POST['num'];
if ($value % 2) {
echo '"'.$value.'" is odd';
} else {
echo '"'.$value.'" is even';
}
}
?>