<html>
<head>
<title>Responsive Calculator in PHP</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
height: 100vh;
}
input[type="number"], select {
padding: 10px;
margin: 10px;
width: 100%;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
button[type="submit"] {
padding: 10px;
margin: 10px;
width: 100%;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button[type="submit"]:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="container">
<form method="post">
<label for="num1">Enter Number 1:</label>
<input type="number" id="num1" name="num1" placeholder="Enter Number 1" required>
<label for="num2">Enter Number 2:</label>
<input type="number" id="num2" name="num2" placeholder="Enter Number 2" required>
<label for="operator">Select Operator:</label>
<select id="operator" name="operator" required>
<option value="+">Addition</option>
<option value="-">Subtraction</option>
<option value="*">Multiplication</option>
<option value="/">Division</option>
</select>
<button type="submit" name="submit">Calculate</button>
</form>
if(isset($_POST['submit'])) {
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$operator = $_POST['operator'];
$result = '';
switch($operator) {
case '+':
$result = $num1 + $num2;
break;
case '-':
$result = $num1 - $num2;
break;
case '*':
$result = $num1 * $num2;
break;
case '/':
$result = $num1 / $num2;
break;
default:
$result = '';
}
if($result !== '') {
echo '<h2>Result:</h2>';
echo '<p>' . $num1 . ' ' . $operator . ' ' . $num2 . ' = ' . $result . '</p>';
}
}
</div>
</body>
</html>
This code creates a basic responsive calculator form using HTML and CSS, and uses PHP to handle the form submission and perform the calculation. The form includes two input fields for entering the numbers to be calculated, a select field for selecting the operator, and a submit button to perform the calculation. When the user submits the form, PHP code handles the form data and performs the appropriate calculation based on the selected operator, and displays the result on the page.