[英]php Form and action in the same page
I have a form like this 我有这样的形式
<html>
<body>
<form action="calc.php" method="post">
Primo numero: <input type="text" name="a" /></br>
Operazione (+-*/): <input type="text" name="b" /></br>
Secondo numero: <input type="text" name="c" />
<input type="submit" />
</form>
</body>
</html>
lied to a separate .php file named calc.php 说谎于名为calc.php的单独的.php文件
that is like 那就像
<?php echo $_POST["a"]; ?><?php echo $_POST["b"]; ?><?php echo $_POST["c"]; ?><strong>=</strong>
<?php
if ($_POST["b"] == "+")
{
echo $_POST["a"] + $_POST["c"];
}
if ($_POST["b"] == "-")
{
echo $_POST["a"] - $_POST["c"];
}
if ($_POST["b"] == "*")
{
echo $_POST["a"] * $_POST["c"];
}
if ($_POST["b"] == "/")
{
echo $_POST["a"] / $_POST["c"];
}
?>
It works fine but I'd like to show the result in the same page 效果很好,但我想在同一页面上显示结果
How can I do? 我能怎么做?
You can put the code in the same file and change the form to: 您可以将代码放在同一文件中,并将表单更改为:
<form action="" method="post">
or 要么
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
to submit it to the same page. 提交到同一页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.