警告:php中未定义的数组键错误

kpbpu008  于 2021-10-10  发布在  Java
关注(0)|答案(1)|浏览(835)

此问题已在此处找到答案

参考-这个符号在php中是什么意思((21个答案)
8小时前关门。
这是我的代码:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>My First Form</title>
  8. </head>
  9. <body>
  10. <form action="form.php" method="get">
  11. Name: <input type="text" name="username">
  12. <br>
  13. Age: <input type="number" name="age"><br>
  14. <input type="submit">
  15. </form>
  16. <?php
  17. echo $_GET["username"];
  18. echo "</br>";
  19. echo $_GET['age'];
  20. ?>
  21. </body>
  22. </html>

我得到一个错误:
警告:第18行c:\users\nambi\desktop\php tutorial\form.php中未定义的数组键“username”
警告:第20行c:\users\nambi\desktop\php tutorial\form.php中未定义的数组键“age”。

yxyvkwin

yxyvkwin1#

在回显之前,应首先检查数组键值是否存在,如下所示:

  1. <?php
  2. if (isset($_GET["username"], $_GET["age"])) {
  3. echo $_GET["username"];
  4. echo "</br>";
  5. echo $_GET['age'];
  6. }

相关问题