PHP Program - Multiplication of two Numbers

We have created below PHP Program to multiply two Numbers. HTML <form> tag with post method is used to submit two numbers.

$_POST variable is used to retrive 2 numbers for performing multiplication.

Here, we have used 2 text field, 1 submit button and 1 form tag.

Example :

<?php
if(isset($_POST['submit']))
{
$num1=$_POST['num1'];
$num2=$_POST['num2'];
$result=$num1*$num2;
$result="Multiplication of " .$num1. " and ".$num2. " : " .$result;
}else
{
$result="";
}

?>
<!DOCTYPE html>
<html>
<head>
<title>PHP Maths Program - Multiplication of two number by aryatechno</title>
</head>
<body>
<table>
<form name="sub" method="post">
<tr>
<td colspan="2"><strong>Maths Multiplication program</strong></td>
</tr>
<tr>
<td>Number 1 :</td>
<td><input type="text" name="num1" value="<?=$_POST['num1'] ?>" required></td>
</tr>
<tr>
<td>Number 2 :</td>
<td><input type="text" name="num2" value="<?=$_POST['num2'] ?>" required></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Multiplication" name="submit" /></td>
</tr>

<tr>
<td colspan="2"><strong><?=$result ?></strong></td>
</tr>

</form>
</table>
</body>
</html>

Output :

Comments

Leave a Reply

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

38381