Sunday, March 5, 2017

Product of Two Numbers in PHP

In this article I wrote a simple program to ask the user to give two numbers and then our program will compute the product of the two numbers given by our user using PHP. The code is very simple and easy to understand you will learn how to use HTML forms to accept and process the values from the user.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing

<?php
error_reporting(0);

$a =$_POST['num1'];
$b =$_POST['num2'];

if (isset($_POST['ok']))
{
$result= $a * $b;
}

if (isset($_POST['clear']))
{
$a="";
$b="";
$result= "";
}

?>
<html><body>
<style>
body {
background-color:lightgreen;
font-family:arial;
font:12px;
}
</style>

<form action="index.php" method="post">
<h3> Product of Two Numbers in PHP </h3>
<br>
Value No. 1 : &nbsp;&nbsp;  <input name="num1" value="<?php echo $a ?>" autofocus required> <br><br>
Value No. 2 : &nbsp;&nbsp;  <input name="num2" value="<?php echo $b ?>" required>
<br><br>
Answer      : &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  
             <input value="<?php if (isset($result)) echo $result ?>" readonly>
<br><br>
<input type="submit" name="ok" value="Ok" title="Click here to find the product.">
&nbsp;&nbsp;&nbsp;
<input type="submit" name="clear" value="Clear" title="Click here to clear the text box.">
</form>
</body></html>




No comments:

Post a Comment