简单的计算器无法正常工作
I want to develop an ez breezy calculator to upload to a page on my site. I have written both the HTML and PHP code to the best of my understanding but still fail to produce an answer to my screen. After I click the "button", I get redirected to a blank screen with no code. When I try it in my site, it takes me back to my home page...every time! Below is all the code...I need help!
<?php
$a=$_POST["'a'"];
$b=$_POST["'b'"];
$c=0;
?>
<meta charset="utf-8">
<html>
<head>
<title>Proposal Sheet Calculator</title>
</head>
<body>
<form method="post" action="/Merchant Calc 1.php">
<h1>How Much Money Are You Losing?</h1>
<p> </p>
<p> </p>
<h2>How many clients walk out your business each month when finding out they don't have the cash or credit to pay?<br/>
<input type="text" name="'a'"><br/></h2>
<h2>What is your average ticket price?<br/>
<input type="text" name="'b'"><br/></h2>
<p> </p>
<h2><input name="calc" type="Submit" value="Show me the numbers" /></h2>
<p> </p>
<p> </p>
<br/>
<p>
<?php
$a = $_POST[‘a’];
$b = $_POST[‘b’];
$c=$a*$b
// should output $a*$b
if(isset($_POST[‘submit’])){
echo "$a * $b";
}
more?<br/>
<input type="text" name="'Y/N'"><br/>
<input name="calc" type="Submit" />
if(isset($_POST[‘submit’]))<br/>
</p>
?>
</form>
</body>
</html>
I don't even get to the "more?" input...it dumps me out before that so I have not done anything below the "more?" lines. And the crazy output of the last if statement...WebMatrix shows no errors.?.?.?.? Thanks in advance!
<?php
error_reporting(0);
?>
<html>
<head>
<title>Proposal Sheet Calculator</title>
</head>
<body>
<form method="post" action="">
<h1>How Much MONEY Are You Losing?</h1>
<p> </p>
<p> </p>
<h2>How many clients walk out your BUSINESS each month when finding out they don't have the cash or credit to pay?<br/>
<input type="text" name="a"><br/></h2>
<h2>What is your average ticket price?<br/>
<input type="text" name="b"><br/></h2>
<p> </p>
<h2><input name="calc" type="Submit" value="Show me the numbers" /></h2>
<p> </p>
<p> </p>
<br/>
<p>
<?php
$a = $_POST["a"];
$b = $_POST["b"];
$c=$a*$b;
// should output $a*$b
if(isset($_POST["calc"])){
echo $c;
}
?><br/>
<input type="text" name="'Y/N'"><br/>
<input name="calc" type="Submit" />
<br/>
</p>
</form>
</body>
</html>
You have few syntax errors, fix them it will work.
Firstly, add semicolon ;
in this line
$c=$a*$b;
^
Next, you are enclosing multiplication operation inside double quotes, so multiplication will now work, it will be considered as string. so remove double quotes.
echo "$a * $b";// will echo number * number
change to
echo $a * $b;// will echo multiplied value.
Next remove action
to your form. I mean make action as action=""
Next access either usnf single quotes or double quotes not both.
$a=$_POST["'a'"];
this should be
$a=$_POST["a"]; or
$a=$_POST['a'];
and also
<input type="text" name="'Y/N'"><br/>
this also
<input type="text" name="Y/N"><br/> or
<input type="text" name='Y/N'><br/>