【问题标题】:Not able to print after getting the values through GET method [duplicate]通过GET方法获取值后无法打印[重复]
【发布时间】:2016-06-15 05:04:45
【问题描述】:

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

【问题讨论】:

  • 你进入if语句了吗?
  • “做不到”是什么意思?你的输出是什么?
  • 当我尝试从单个文本框中回显值时。它可以工作,但是当我对 2 个文本框做同样的事情时。 echo 语句不起作用。

标签: php


【解决方案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>

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

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

【讨论】:

    【解决方案2】:
    <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">
    

    【讨论】:

      猜你喜欢
      • 2016-03-26
      • 1970-01-01
      • 2018-03-28
      • 2021-05-24
      • 1970-01-01
      • 2018-04-02
      • 2014-02-08
      • 1970-01-01
      • 2021-10-08
      相关资源
      最近更新 更多