Get Website Learn Coding Tech Story

PHP Programming Examples

<!DOCTYPE html>
<html>
	<head>
		<title>Greatest Number</title>
	</head>
	<body>

		/* "$_SERVER['PHP_SELF']" get the current URL of the file */
		<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
			<input type="text" name="fst_no" placeholder="First Number" />
			<input type="text" name="snd_no" placeholder="Second Number" />
			<input type="submit" />
		</form>
		<?php

			/* 'isset()' check the variable exists or not */
			if(isset($_POST['fst_no']) && isset($_POST['snd_no'])) {

				/* 'is_numeric()' check the variable contain number or not */
				if(is_numeric($_POST['fst_no']) && is_numeric($_POST['snd_no'])) {

					/* Compare two numbers */
					if($_POST['fst_no'] > $_POST['snd_no']) 
						echo $_POST['fst_no']." is Greatest Number!";
					else
						echo $_POST['snd_no']." is Greatest Number!";
				}
				else
					echo "Not a valid number!";
			}
		?>
	</body>
</html>


          /****** Output ******/
          

Input:

fst_no = 7

snd_no = 4

7 is the Greatest Number!


----------------------------------------------


Input:

fst_no = ab

snd_no = cd

Not a valid number!

Learn more about isset and is_numeric