2014-01-19 52 views
0

为什么这不起作用。我看了很多网站,这看起来很长时间。好吧,不,不。获取按钮输入

编辑的代码到这一点,回声按下时,我甚至还没有按下按钮

<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"; 



} 



     ?> 
+0

我将这个逐字记录复制到一个空白的PHP文件中,它工作正常。你应该关闭你的'

'标签,并且密码输入需要是'type =“password”'。 – TiiJ7

+0

其工作...我只是复制你的代码,并在一个PHP文件中运行。 –

+0

它不起作用当我没有点击按钮时按下了回声..... – user3211972

回答

2

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

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"; 


    } 
0

你需要summat像

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

+0

我不确定它是否需要一个'action'才能成为有效的HTML,但它会很快乐地发布给自己。 – halfer

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"; 
} 
?>