获取按钮输入

时间:2014-01-19 11:24:11

标签: php

为什么这不起作用。我看了很多网站,这看起来很长。好不,没有。

当我甚至没有按下按钮

时,编辑了这个代码
<form method='POST' name="form1" action="index.php">

        Username: <input name="username"><br>
        Password: <input name="password"><br>


        <input type = 'submit' name = 'submit' value = 'click me'>



    </form> 

        <?php

        if (isset($_POST['submit'])){

            echo "Pressed button";



}



        ?>

4 个答案:

答案 0 :(得分:2)

您错过了标记<form></form>。因此它不起作用

答案 1 :(得分:1)

你需要添加表单标签,并在表单的动作标签中给出你的php页面名称。这是index.php,但您需要指定自己的脚本名称。

     <form name="form1" method="post" action="index.php">
    Username: <input name="username"><br>
    Password: <input name="password"><br>


    <input type = 'submit' name = 'submit' value = 'click me'>
    </form>


    <?php

    if (isset($_POST['submit'])){

        echo "Pressed button";


    }

答案 2 :(得分:0)

你需要像

这样的summat
<form method="post" action="myscript.php">

答案 3 :(得分:0)

即使没有关闭表单标记,您的代码仍在运行。但下面是使用表格的正式方式。

<form method='post' action="">
    Username: <input name="username"><br>
    Password: <input name="password"><br>
    <input type = 'submit' name = 'submit' value = 'click me'>
</form>

<?php
if (isset($_POST['submit'])) {

    echo "Pressed button";
}
?>