[英]Can I pass a variable from one html page to another html page using php?
The following code is not working: 以下代码不起作用:
code on page 1: 第1页的代码:
<form action="phpTutorial.html" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
code on page 2: 第2页的代码:
<br />
Welcome <?php echo $_Post["fname"]; ?>!<br ?>
You are <?php echo $_Post["age"]; ?> years old.
<br />
Try: 尝试:
echo $_POST["fname"]
The inbuilt variables (is there a better name for those?) are all referenced in capitals, and PHP variable names are case sensitive. 内置变量(是否有更好的名称?)全部用大写字母引用,PHP变量名称区分大小写。
Action in the form should be action="phpTutorial.php"
instead of action="phpTutorial.html"
and phpTutorial.php
should have 表单中的action="phpTutorial.php"
应为action="phpTutorial.php"
而不是action="phpTutorial.html"
而phpTutorial.php
应具有
<br />
Welcome <?php echo $_POST["fname"]; ?>!<br ?>
You are <?php echo $_POST["age"]; ?> years old.
<br />
When you will submit a form it'll launch the file in the from's action attribute you gave and in this case you give the name of the php file and it should be phpTutorial.php
. 当您提交表单时,它将在您提供的from的action属性中启动文件,在这种情况下,您将提供php文件的名称,该文件的名称应为phpTutorial.php
。
Since you are using PHP on your code, so file name should be phpTutorial.php instead of phpTutorial.html. 由于您在代码上使用PHP,因此文件名应为phpTutorial.php而不是phpTutorial.html。 Correct Form action name 正确的表单动作名称
And phpTutorial.php should have following code: phpTutorial.php应该具有以下代码:
<br />
Welcome <?php echo $_Post["fname"]; ?>!<br ?>
You are <?php echo $_Post["age"]; ?> years old.
<br />
$_Post should be replaced by $_POST . $ _Post应该替换为$ _POST 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.