Program

<?php
$msgres = "";
$value1 = "";
$alert = false;
$display = false;
if(isset($_POST["result"]) && is_numeric($_POST["val_1"]) && $_POST["val_1"] != 0) {
	$virable_A = $_POST["val_1"];
	$table = $virable_A;
	for ($num = 1; $num <= 10; $num++) {
		$res = $table * $num;
		$msgres .= "<p>$table * $num = $res </p>";
	}
	$display = true;
   $alert = false;
}elseif(isset($_POST["result"]) && !is_numeric($_POST["val_1"])){
   $alert = true;
   $msgres = "Invalid Data ";
} else {
   $value1="";
}
?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<title>Table Print in PHP Using Forms</title>
	</head>
	<body>
		<div id="php">
			<h2>Table Print in PHP Using Forms</h2>
			<form method="POST">
				<p> Enter The Digit :
					<input type="text" name="val_1" value="<?php echo "$value1"; ?>" />
					<input type="submit" name="result" value="Result">
				</p>
			</form>
		</div>
		<?php
	if($display) {
		echo "<div class='resultdiv'>  $msgres </div>";
	}
   if($alert){
      echo "<h3>  $msgres </h3>";
   }
		?>
	</body>
</html>

Result

45 * 1 = 45
45 * 2 = 90
45 * 3 = 135
45 * 4 = 180
45 * 5 = 225
45 * 6 = 270
45 * 7 = 315
45 * 8 = 360
45 * 9 = 405
45 * 10 = 450

Demo

SDUTFEV10

(Visited 120 times, 1 visits today)
Share with Friends :

Leave a Reply

Your email address will not be published. Required fields are marked *