我试图弄清楚如何让变量 $_GET 工作,以便 H1 标签变成用户估算的内容



我想回答的问题在下面

  1. 创建一个名为lab2.PHP的新PHP文件
  2. 在里面,添加HTML骨架代码并给出其标题"Lab Week 2">
  3. 在body标签中,创建一个h1标签,上面写着";输入你最喜欢的音乐艺术家的名字">
  4. 在body标记中添加一个section标记
  5. 创建一个表单标记,并使用$_GET方法让用户输入他们最喜欢的艺术家。将用户输入存储到变量中
  6. 创建一个提交按钮,供用户输入他们喜爱的艺术家
  7. 检查变量是否为空
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Fav Artist</title>
<meta name="author" content="Sean Kingston">
<meta name="viewport" content="with=device-width, initial-scale=1.0">
</head>
<body>
<!-- H1 tag I want to change once the user clicks on submit button-->
<h1> Enter the name of your favourite musical artist </h1>
<!--Form-->
<form method="get">
<input type="text" name="name" />
<input type="submit" value="Submit" name="sub">
</form>
</body>
</html>
<?php
//isset not working//
if(isset($_GET['name'])){
echo $_GET['name'];
}
?>
<?php
show_source(FILE);
</html>
?>

我大胆猜测一下,这是一项教育任务。

不过,以下是我对任务的理解。

<?php
//1.Create a new PHP file named lab2.php.
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Lab Week 2</title><!-- 2.Inside, add the HTML skeleton code and give its title “Lab Week 2"  -->
</head>
<body>
<h1><?php
// 5. use the $_GET method to get users to input their favorite artist. Store the user input into variables.
$favouriteMusicalArtist = $_GET['favourite_musical_artist'];
// 7.Check whether the variable is empty or not.
if (empty($favouriteMusicalArtist)) {
//3.Within the body tag, create a h1 tag that says "Enter the name of your favourite musical artist"
echo 'Enter the name of your favourite musical artist';
} else {
echo 'Your favourite musical artist is: ' . $favouriteMusicalArtist;
}
?></h1>
<!-- 4.Add a section tag inside the body tag. -->
<section>
<!-- 5.Create a form tag -->
<form method="GET">
<input type="text" name="favourite_musical_artist"/>
<!-- 6.Create a submit button for the user to input their favorite artist.  -->
<button type="submit">Submit</button>
</form>
</section>
</body>
</html>

现在,如果这是某种测试,不要只是复制互联网。摆弄代码,试着学习一些东西:-(

最新更新