单击按钮时不会调用函数

Function is not getting called on clicking the button

此代码在first.php


function fas(){
    echo "fuction";
    echo "Anything";
}

if(isset($_POST['btn'])){
    fas();
}
?>

second.php

中的代码
<?php 
include 'first.php'
?>

<!DOCTYPE html>
<head>
    <title>Document</title>
</head>
<body>
    <button type= "submit" name = "btn"> click this</button>
</body>
</html>

单击按钮时,函数 fas 未被调用。有什么问题?

您可以将按钮放在 form 标记中,然后按钮像这样:

<form action="/" method="post">
  <button type="submit">Submit</button>
</form>

或者你可以这样做:

<button onclick="function_name()">Submit</button>

第二个将直接调用函数,而不是像表单那样转到单独的 link。