Create an HTML page as shown below by writing PHP script for a simple calculator
ID: 3593539 • Letter: C
Question
Create an HTML page as shown below by writing PHP script for a simple calculator which can perform
the basic operations of addition, subtraction, multiplication, division and mod on the given two numbers
and show result to user. You have to perform the validation check on user input values and show error
message in case if user input give invalid input.
For the given page use internal style CSS with the following details.
h1 color: green
h2 color: red
Box model with background color “lightgrey” and border solid blue.
All text and box should be center aligned
Add footer for your page containing your name and your contact e-mail address as a hyperlink.
Explanation / Answer
imdex.html
<head>
<meta charset="utf-8">
<title>Calculator</title>
</head>
<body>
<form method="post" attribute="post" action="disp_form.php">
<p>First Value:<br/>
<input type="text" id="first" name="first"></p>
<p>Second Value:<br/>
<input type="text" id="second" name="second"></p>
<select name="operaion">
<option value="add">+</option>
<option value="subtract">-</option>
<option value="divison">/</option>
<option value="multiply">*</option>
</select>
<button type="submit" name="answer" id="answer" value="answer">Calculate</button>
</form>
</body>
</html>
//disp_form.php
<html>
<body>
<form method="post" attribute="post" action="disp_form.php">
<p>First Value:<br/>
<input type="text" name="first"></p>
<p>Second Value:<br/>
<input type="text" name="second"></p>
<select name="operaion">
<option value="add">+</option>
<option value="subtract">-</option>
<option value="divison">/</option>
<option value="multiply">*</option>
</select>
<button type="submit" name="answer" id="answer" value="answer">Calculate</button>
</form>
<?php
First Value: echo $first = $_POST["first"];
Second Value: echo $second= $_POST['second'];
if($_POST['operaion'] == 'add') {
Result echo $first + $second;
}
else if($_POST['operaion'] == 'subtract') {
echo $first - $second;
}
else if($_POST['operaion'] == 'multiply') {
echo $first * $second;
}
else if($_POST['operaion'] == 'divide') {
echo $first / $second;
}
?>
</html>
</body>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.