
I have done the full coding of a sticky form. It is a simple calculator. Whenever I input the value and press "add" or"minus" or "multiply"..etc..etc..and also the reset button the result does not display. Please see my coding below...and advice me what is the problem, and what it need me to done to solve it.
<html>
<head>
<title>Simple Calculator</title>
<?php
if (isset($_POST['submitted']) && !isset($_POST['reset'])){
if (isset($_POST['add'])) {
$add = $_POST['number1'] + $_POST['number2'];
echo "Add: ".$_POST['number1']." + ".$_POST['number2']." = ".$add;
}
}
if (isset($_POST['minus'])) {
$minus = $_POST['number1'] - $_POST['number2'];
echo "Minus: ".$_POST['number1']." - ".$_POST['number2']." = ".$minus;
} if (isset($_POST['multiply'])) {
$multiply = $_POST['number1'] * $_POST['number2'];
echo "Multiply: ".$_POST['number1']." * ".$_POST['number2']." = ".$multiply;
} if (isset($_POST['divide'])) {
$divide = $_POST['number1'] / $_POST['number2'];
echo "Divide: ".$_POST['number1']." / ".$_POST['number2']." = ".$divide;
}
?>
<script type="text/javascript">
</script>
</head>
<body>
<h1>Simple Calculator</h1>
<form action="simple_calculator.php" method="post">
<p>Number 1: <input type="text" name="number1" size="20" value="<?php if(isset($_POST['number1'])) echo $_POST['number1'];?>"/></p>
<p>Number 2: <input type="text" name="number2" size="20" value="<?php if(isset($_POST['number2'])) echo $_POST['number2'];?>"/></p>
<input type="button" id="add" value="Add" />
<input type="button" id="minus" value="Minus" />
<input type="button" id="multiply" value="Multiply" />
<input type="button" id="divide" value="Divide" />
<input type="submit" id="reset" value="Reset" />
<input type="hidden" id="submitted" value="TRUE" />
</form>
</body>
</html>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.