通过GET方法获取值后无法打印


Not able to print after getting the values through GET method

我正在尝试通过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">

当您提交表单时,应该有一个提交按钮。在您的情况下,没有提交按钮。这就是表格从未提交的原因。

请尝试以下示例:

<!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>

在您的情况下,表格从未提交过,因为

<input type = "button" name="submit" value="Submit">
<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">