这是我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First Form</title>
</head>
<body>
<form action="form.php" method="get">
Name: <input type="text" name="username">
<br>
Age: <input type="number" name="age"><br>
<input type="submit">
</form>
<?php
echo $_GET["username"];
echo "</br>";
echo $_GET['age'];
?>
</body>
</html>
我得到一个错误:
警告:未定义数组键"用户名" users nambi desktop php Tutorialform.php on line 18
警告:未定义数组键"age" users nambi desktop php Tutorialform.php in line 20.
在回显之前应该先检查数组key-value是否存在,如下所示:
<?php
if (isset($_GET["username"], $_GET["age"])) {
echo $_GET["username"];
echo "</br>";
echo $_GET['age'];
}