我在PHP中使用Html表单,我如何使用$_GET来分配给这个特定代码中IF语句中使用的变量


I am using a Html form with PHP, how do i use $_GET to be assigned to a variable to be used in an IF statement in this specific code

这是我的html页面:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Hello and welcome to my site</title>
</head>
<body>
<p>are these 2 numbers equal? type yes or no in the box</p>
<p2>one</p2> and  eight
<form action="welcome_get.php" method="get">
Answer: <input type="text" name="name"><br>
<input type="submit">
</form>
</body>
</html>

这是我的新php页面,包含以前的答案,我有新的错误

<html>
<body>
<?php
var_dump($_GET['name']);
$answer = $_GET['name'];
$saying = "congratulations";
if ($answer == "yes"){
echo  $saying;
}
?>

</body>
</html>

新错误指的是我的php页面welcome_get.php

var_dump($_GET['name']);

此外,要查看所有可用的GET参数:

var_dump($_GET)

分配给新变量:

if(!empty($_GET['name'])){
    $answer = $_GET['name'];
    if($answer == 'something'){
        // do something
    }
}

您可以使用isset函数检查$_GET['var']是否设置为

if(isset($_GET['name']({$answer=$_GET['name'];$saying="祝贺";if($answer=="是"({echo$saying;}}