<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> calculator </title>
</head>
<body bgcolor="goldenrod">
<center>
<h1>Calculator Application</h1>
<form action="projectcal.php" method="POST">
Type value1:<br/><input type="text" name="value1"><br/><br/>
Type value2:<br/><input type="text" name="value2"><br/><br/>
Calculation sign:<br/><input type="text" name="action"><br/><br/>
<input type="submit" name="submit" value="Submit">
</form>
</center>
above..created html form for putting the value...and below is the source code..
<?php
if(isset($_POST['submit']))
{
storing in local var
$value_1=$_POST['value1'];
$value_2=$_POST['value2'];
$action=$_POST['action'];
}
if($value_1=='' || $value_2=='') //errorline
{
echo "<script>alert('Please Enter Any Value')</script>"; //if user enters blank value
exit();
}
if($action=='')
{
echo "<script>alert('Please Enter the Operator Sign')</script>";
}
using array for shorter code
if(in_array($action,array('+','-','*','/')))
if user enters any of the the above sign in action field..than it will echo the value....and i am getting the result by using this ...but error is not going from line 29
switch($action)
{
case '+':
echo "Your answer is ";
echo $value_1+$value_2;
break;
case '-':
echo "Your answer is ";
echo $value_1-$value_2;
break;
case '*':
echo "Your answer is ";
echo $value_1*$value_2;
break;
case '/':
echo "Your answer is ";
echo $value_1/$value_2;
break;
}
?>
</body>
</html>
hope its clear now