最終更新日:190422原本2019-01-24 

フォーム送信時に特定のPHP関数を呼び出す

フォームとphpスクリプトの両方が同じページにあるフォームの送信で特定のphp関数を呼び出そうとしていました。私のコードは下にあります(それは機能していないので、私は助けが必要です)

<html>
    <body>
    <form method="post" action="display()">
        <input type="text" name="studentname">
        <input type="submit" value="click">
    </form>
    <?php
        function display()
        {
            echo "hello".$_POST["studentname"];
        }
    ?>
    </body>
</html>
ベストアンサー
次の行で

<form method="post" action="display()">

アクションはあなたのスクリプトの名前であるべきで、あなたは関数を呼ぶべきです。

<form method="post" action="yourFileName.php">
    <input type="text" name="studentname">
    <input type="submit" value="click" name="submit"> <!-- assign a name for the button -->
</form>

<?php
function display()
{
    echo "hello ".$_POST["studentname"];
}
if(isset($_POST['submit']))
{
   display();
} 
?>

転載記事の出典を記入してください: フォーム送信時に特定のPHP関数を呼び出す - コードログ