在php上执行函数

在php上执行函数,php,html,forms,submit-button,Php,Html,Forms,Submit Button,我最近开始了php编程。但是,在php文件上运行函数时遇到了一个问题。我的php文件如下所示: <html> <head> <meta http-equiv="content-type" content="text/html" /> <meta name="author" content="aaaaa" /> <title>Untitled 3</title> </head> <

我最近开始了php编程。但是,在php文件上运行函数时遇到了一个问题。我的php文件如下所示:

<html>
<head>
    <meta http-equiv="content-type" content="text/html" />
    <meta name="author" content="aaaaa" />

    <title>Untitled 3</title>
</head>

<body>

<form method="post" action="Test()" >
<input type="submit" name="submit" value="submit"/>

</form>

<?php
echo "Hello";
function Test()
{
    echo "Goodbye";
}
?>

</body>
</html>

无标题3

运行程序后,会看到一个网页,上面有一个名为submit的按钮和一个单词“Hello”。但是,单击按钮后,会看到“无法显示此页面”的网页。但我尊重“再见”这个词。我将php代码转移到另一个文件,但问题没有得到解决

表单中的操作与JavaScript不同。您正在尝试在submit上运行Test(),这不是一件容易的事情。您想要的是action to be action=“”

实际上,你应该这样做:

<html>
<head>
    <meta http-equiv="content-type" content="text/html" />
    <meta name="author" content="aaaaa" />

    <title>Untitled 3</title>
</head>

<body>

<form method="post" action="" >
<input type="submit" name="submit" value="submit"/>
</form>
<?php
    echo "Hello";

if(isset($_POST['submit'])){
    echo "Goodbye";
}

?>

</body>
</html>

无标题3
如果你想使用一个函数

<html>
<head>
    <meta http-equiv="content-type" content="text/html" />
    <meta name="author" content="aaaaa" />

    <title>Untitled 3</title>
</head>

<body>

<form method="post" action="" >
<input type="submit" name="submit" value="submit"/>
</form>
<?php
    echo "Hello";

function test(){
   echo "Goodbye";
}

if(isset($_POST['submit'])){
    test();
}

?>

</body>
</html>

无标题3
假设文件名为test.php,您将所有代码放在其中,因此操作值应为test.php

<form method="post" action="test.php" >


php标记@chris85上还有132个点,您可以一次关闭这些点;-)我打赌你等不及了!Lol在看到您在其中一个答案中留下的评论“但是,再次观察到“此页面无法显示”的网页后,我认为您正在尝试将其作为
文件运行://
,而不是作为主机运行。我正在编写代码并由phpDesigner 8运行。我将本地主机设置在计算机的文件夹中。理论上你是正确的,但他们希望使用的功能如何;这会发生什么?我会编辑它,但在这个实例中不需要函数..“在这个实例中不需要函数”-是的,但是如果他们“想要”使用函数,以及可能的JS方法和ajax等等,该怎么办。?我们真的不知道别人脑子里在想什么;-)他们仍然可以声明他们的
函数测试()
,但他们只会将其称为他们提交的页面:
<代码>@Fred ii-这是为他们想要的案子编辑的。