不工作的简单计算器


Simple Calculator that isn't working

我想开发一个轻松的计算器上传到我的网站上的页面。我尽我所能编写了HTML和PHP代码,但仍然无法在屏幕上生成答案。在我点击"按钮"后,我被重定向到一个没有代码的空白屏幕。当我在我的网站上尝试它时,它把我带回到我的主页…每一次!下面是所有的代码…我需要帮助!

<?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>&nbsp;</p>
<p>&nbsp;</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>&nbsp;</p>
<h2><input name="calc" type="Submit" value="Show me the numbers" /></h2>
<p>&nbsp;</p>
<p>&nbsp;</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>

我甚至没有看到"more?"的输入…它在那之前就把我甩出去了,所以我没有做任何低于"更多?"的事情。最后一个if语句的疯狂输出…WebMatrix没有显示错误……提前感谢!

<?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>&nbsp;</p>
<p>&nbsp;</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>&nbsp;</p>
<h2><input name="calc" type="Submit" value="Show me the numbers" /></h2>
<p>&nbsp;</p>
<p>&nbsp;</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>

你有一些语法错误,修复它们,它将工作

首先,在这行

中添加分号;
$c=$a*$b;
        ^

接下来,您将乘法操作括在双引号内,因此乘法现在可以工作了,它将被视为字符串。所以去掉双引号

echo "$a * $b";// will echo number * number

改为

echo $a * $b;// will echo multiplied value.

下一步删除action到您的表单。我的意思是采取行动作为action=""

下一步访问usnf单引号或双引号,但不能同时使用。

$a=$_POST["'a'"];

应该是

$a=$_POST["a"]; or 
$a=$_POST['a'];

<input type="text" name="'Y/N'"><br/>

这也

<input type="text" name="Y/N"><br/> or
<input type="text" name='Y/N'><br/>