PHP表单标签难度


PHP form tag difficulty

我想制作一个应用程序表单,用PHP和CSS编写,我的问题是:在标签中,我设置了一个提交按钮,并在将我的名字写入文本栏后,我得到的句子"我输入的名字是:"在我的网页的左上角。我不希望这句话出现在我的页面上方。我想要这个句子下面的文本框,我输入我的名字。让这句话出现在我的网页顶部意味着一个糟糕的网页设计,但我不知道如何使这句话出现在我想要它出现的地方。好吧,当我在我的程序中摆脱了所有其他代码(即CSS代码等),只是有标签本身(连同句子"我输入的名字是:"),我输入名字Gavin,我得到的是"我输入的名字是:Gavin",这句话出现在文本框上方。似乎这个位置是默认的,没有什么可以做的。我说的对吗?是否有任何方法来重新定位我的句子,使它出现在文本框下面。此外,是否有任何方法,使我的文本框消失一旦我已经输入我的名字,并点击提交?

<?php
//brownuniversity.php
if (!empty($_POST['name'])) {
    echo "Hello, {$_POST["name"]}, and welcome.";
}
?>
<html>
<head>
  <title>Image</title>
<style>
p.pos_fixed {
  position: fixed;
  top: 30px;
  right: 50px;
  color: black;
}
h4 {
  text-decoration: underline;
}
</style>
</head>
<body>
<h4>Application Form</h4>
<img src="alphacentauri.jpg" alt="starcluster" width="200" height="200" /><br/><br/>
<p class="pos_fixed">
  <b>Brown University:</b>
  <br><br><br>
  <b>Department of Physics:</b>
</p>
<ul>
  <li>question1</li>
  <li>question2</li>
</ul>
The name that I have entered is:
<form action="brownuniversity.php" method="post">
  If you want to take part in this star-gazing project, enter your name:
  <input type="text"  name="name">
  <input type="submit">
</form>

在我的网页的左上角

因为那是你放它的地方。看一下:

...
if(!empty($_POST['name'])) {
    echo "Hello, {$_POST["name"]}, and welcome.";
}
echo <<<_END
<html>
...

在HTML开始之前就输出了句子。所以它当然会是。

如果您希望它位于页面的特定位置,则在该位置输出它。例如:

...
<?php
if(!empty($_POST['name'])) {
?>
    The name that I have entered is: <?php echo $_POST["name"]; ?>
<?php
}
?>
<form action="brownuniversity.php"  method="post">
...

对于初学者,整理代码。

希望能成功。

<?php
//brownuniversity.php
if (!empty($_POST['name'])) {
    echo "Hello, {$_POST["name"]}, and welcome.";
}
?>
<html>
<head>
  <title>Image</title>
<style>
p.pos_fixed {
  position: fixed;
  top: 30px;
  right: 50px;
  color: black;
}
h4 {
  text-decoration: underline;
}
</style>
</head>
<body>
<h4>Application Form</h4>
<img src="alphacentauri.jpg" alt="starcluster" width="200" height="200" /><br/><br/>
<p class="pos_fixed">
  <b>Brown University:</b>
  <br><br><br>
  <b>Department of Physics:</b>
</p>
<ul>
  <li>question1</li>
  <li>question2</li>
</ul>
The name that I have entered is:
<?php
//brownuniversity.php
if (isset($_POST['name'])) {
    $_POST["name"];
}
?>
<form action="brownuniversity.php" method="post">
  If you want to take part in this star-gazing project, enter your name:
  <input type="text"  name="name">
  <input type="submit">
</form>