PHP 提交按钮不起作用。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12377368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:27:03  来源:igfitidea点击:

PHP submit button not working.

phphtml

提问by user1663978

<?php
if(isset($_POST['submit'])){
header('Location: http://www.rate.ee');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>
        </title>
    </head>
    <body>
        <input type="submit" name="submit" id="submit" class="button" value="Submit"/>
    </body>
</html>

This is my code. Very simple, isn't it. But it doesn't work and I don't get it.. I always thought that PHP only executes when I load the page, but the other page where I use same code works very well without JS..

这是我的代码。很简单,不是吗。但它不起作用,我不明白..我一直认为PHP只在我加载页面时执行,但我使用相同代码的另一个页面在没有JS的情况下工作得很好..

回答by andrewsi

You need to wrap your button in a <form>tag:

您需要将按钮包装在<form>标签中:

<form action="" method="post">
<input type="submit" name="submit" id="submit" class="button" value="Submit"/>
</form>

回答by JvdBerg

You need a form surrounding the input.

您需要一个围绕输入的表单。

<body>
<form action="welcome.php" method="post">
  <input type="submit" name="submit" id="submit" class="button" value="Submit"/>
</form>
</body>
</html>

回答by j08691

You have no form tag and even if you did it would need the method="post" attribute.

你没有表单标签,即使你做了它也需要 method="post" 属性。

<form method="post" action="<?php echo $_SERVER[PHP_SELF]?>">
    <input type="submit" name="submit" id="submit" class="button" value="Submit"/>
</form>