2016-03-02 52 views
-1

我想通過GET方法獲取兩個文本框的值。但是當我嘗試打印他們兩個。我無法做到。當我用單個文本框完成代碼時,代碼完美地工作。通過GET方法獲取值後無法打印

<?php 
if(isset($_GET['name']) && isset($_GET['id'])) 
{ 

$username = $_GET['name']; 
$userid = $_GET['id']; 
echo 'Hi '.$username.'<br>'; 
echo "Emp Id is ".$userid; 
} 
?> 

<form action="contact-DB.php" method="GET"> 
Enter Employee Name : <input type = "text" name = "name"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Enter Employee ID : <input type = "text" name = "id"> 
<input type = "button" name="submit" value="Submit"> 
+0

形式? – Unex

+0

「無法做到」是什麼意思?你的輸出是什麼? –

+0

當我嘗試從單個文本框中回顯值時。它的作品,但是當我做同樣的2個文本框。回聲聲明不起作用。 – user3196569

回答

1

當您提交表單時,應該有一個提交按鈕。在你的情況下,沒有提交按鈕。這就是表單從未提交的原因。

請嘗試下面的例子:

<!DOCTYPE html> 
<html> 
    <body> 
     <?php 
      if(isset($_GET['name']) && isset($_GET['id'])) { 

       $username = $_GET['name']; 
       $userid = $_GET['id']; 
       echo 'Hi '.$username.'<br>'; 
       echo "Emp Id is ".$userid; 
      } 
     ?> 
     <form action="contact-DB.php" method="GET"> 
      Enter Employee Name : 
      <input type = "text" name = "name"> 
      <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      Enter Employee ID : 
      <input type = "text" name = "id"> 
      <input type = "submit" name="submit" value="Submit"> 
     </form> 
    </body> 
</html> 

在你的情況從來沒有提交,因爲你在if語句得到

<input type = "button" name="submit" value="Submit"> 
0
<input type="button" /> buttons will not submit a form - they don't do anything by default. They're generally used in conjunction with JavaScript as part of an AJAX application. 

<input type="submit"> buttons will submit the form they are in when the user clicks on them, unless you specify otherwise with JavaScript. 

所以用這個

<input type="submit" value="Submit" name="submit">