Simple calculator program in php using if else

A Simple calculator program in php using if else. Using this program we can run the simple calculator program in browser through xampp. Calculating machine is another name for it. a small electrical or mechanical device that conducts computations and necessitates personal intervention for each operation a person who is in charge of such a machine The goal of a calculator is to perform accurate calculations quickly. It is obvious that, to the extent possible, a calculator should relieve the user of the need to perform mental calculations and rely on paper.

<!DOCTYPE html>

<head>
<title>Welcome to inlarn.com</title>
</head>

<?php
$a = $_POST['a'];
$b = $_POST['b'];
$operator = $_POST['operator'];
$result = '';
if (is_numeric($a) && is_numeric($b)) {
switch ($operator) {
case "Add":
$result = $a + $b;
break;
case "Subtract":
$result = $a - $b;
break;
case "Multiply":
$result = $a * $b;
break;
case "Divide":
$result = $a / $b;
}
}

?>

<body>
<div id="page-wrap">
<h1>calculator</h1>
<form action="" method="post" id="quiz-form">
<p>
<input type="number" name="a" id="a" required="required" value="<?php echo $a; ?>" /> <b>First number</b>
</p>
<p>
<input type="number" name="b" id="b" required="required" value="<?php echo $b; ?>" /> <b>Second number</b>
</p>
<p>
<input readonly="readonly" name="result" value="<?php echo $result; ?>"> <b>Result</b>
</p>
<input type="submit" name="operator" value="Add" />
<input type="submit" name="operator" value="Subtract" />
<input type="submit" name="operator" value="Multiply" />
<input type="submit" name="operator" value="Divide" />
</form>
</div>
</body>
</html>

calculator

 First number

 Second number

 Result

   

Uses of GET and POST in calculator program in php

The POST method uses HTTP headers to send data. The data is encoded as specified for the GET method and stored in the QUERY STRING header. The data size that can be sent with the POST method is unrestricted. Both ASCII and binary data can be sent using the POST method.

The HTTP request methods Get and Post are used inside the form> tag to submit form data to the server. The HTTP protocol allows communication between the client and the server, with the client being a browser and the server being a program operating on the computer system that hosts your website.

What is Wrap keyword in php

When a string reaches a certain length, the wordwrap() method wraps it into new lines. Note that this function may result in white spaces at the start of lines. The wordwrap() function wraps a string into a predetermined amount of characters. Using a string break character, wraps a string to a specified amount of characters. The string that will be entered. The length of the string at which it will be wrapped.

How to create simple button in calculator using html and css

Definition and Application The submit button is defined by the input type=”submit”>, which submits all form values to a form-handler. In most cases, the form-handler is a server page with a script for processing the submitted data. The form’s action element specifies the form’s handler.