2013-04-06 57 views
0

我的表單內的數據不會發送到search.php。我也使用Twitter引導程序。HTML get方法不會發送數據到PHP

<form class="form-search" action="search.php" method="get"> 
      <fieldset> 
      <input type="text" placeholder="Username" id="username" class="input-medium search-query"> 
      <button type="submit" id="srchUser" class="btn">Search</button> 
      </fieldset> 
      </form> 

我的PHP

  <h2>Searched <?php print $_GET['username']; ?>; Returned 5 Results from Query.</h2> 

5是靜態的,放在那裏供臨時使用。當我使用表單發送數據時,出現此錯誤。

注意:未定義指數:用戶名在C:\ XAMPP \ htdocs中\網絡\統計\上線40

含義的search.php數據未發送到$ _GET。

回答

1

你需要一個名稱添加到輸入基礎上,輸入名稱不是ID

<input type="text" name='username' placeholder="Username" id="username" class="input-medium search-query"> 

$ _GET作品。當您按下提交時名稱會被傳遞,ID只是標識頁面上的輸入。

0

除了您指定的所有其他屬性外,還需要name =「username」。

0

表單看起來應該像

<form class="form-search" action="search.php" method="get"> 
     <fieldset> 
     <input type="text" name="username" placeholder="Username" id="username" class="input-medium search-query"> 
     <button type="submit" id="srchUser" class="btn">Search</button> 
     </fieldset> 
    </form> 

我已經添加到您的輸入name="username"所以它可以發送GET變量通過使用輸入項目名稱屬性到PHP