检查Isset和Echo''在屏幕上
我是一个菜鸟,我开始学习PHP。我制作了一个简单的表格,我想用“ Echo”在浏览器中输入的名称。我发现我必须使用“如果Isset”,然后成功编写了该解决方案。但是我很难将其列入一行,请提供帮助:
<form action="UserInput.php" method="get">
Name: <input type="text" name="name">
<input type="submit">
</form>
/* This is working great!
<?php
if (isset($_GET['name'])) {
echo $_GET['name'];
} else {
// do nothing
}
?>
*/
我想检查是否输入了“名称”,如果输入echo $ _get ['name'];否则,我希望“名称”的价值为“匿名”。根据文档,这是我写的:
$name = isset($_GET['name']) ? echo $_GET['name']; : 'anonymous';
我知道我的错误是在echo $ _get ['name'];
中。我只是不知道如何用“ Echo”在屏幕上表现出“名称”的显示。
I'm a noob and I started learning PHP. I made a simple form and I wanted to get the name I enter inside the browser with "ECHO". I figured out that I have to use "if isset" and I successfully wrote that solution. But I struggle to put it in one line, please help:
<form action="UserInput.php" method="get">
Name: <input type="text" name="name">
<input type="submit">
</form>
/* This is working great!
<?php
if (isset($_GET['name'])) {
echo $_GET['name'];
} else {
// do nothing
}
?>
*/
I want to check if 'name' was entered and if entered echo $_GET['name']; otherwise I want the value for 'name' to be 'anonymous'. According to the documentation here's what I wrote:
$name = isset($_GET['name']) ? echo $_GET['name']; : 'anonymous';
I know my error is in echo $_GET['name'];
. I just don't know how to formulate the showing of 'name' on the screen with 'echo'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
分配变量时,您不使用
echo
。在现代php中,您可以使用零煤的操作员:
You don't use
echo
when you're assigning a variable.In modern PHP you can use the null-coalescing operator: