2016-03-02 117 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">