2014-01-19 53 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"; 
} 
?>