简体   繁体   English

我可以使用php将变量从一个html页面传递到另一个html页面吗?

[英]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.

相关问题 从一页获取HTML数据属性或ID值,并将其作为PHP变量传递到另一页 - Get HTML data attribute or ID value from one page and pass to another page as PHP variable 有没有一种方法可以使用按钮(html / php)将php变量传递到另一个页面? - Is there a way to pass a php variable to another page using a button (html/php)? 将变量从HTML页面传递到PHP脚本 - Pass Variable From HTML Page To PHP Script 无法使用jQuery将变量从HTML传递到PHP页面 - Unable to Pass variable from html to php page using jquery 如何将变量从一页传递到另一页? - How can i pass a variable from one page to another? 将一个php变量从一个页面传递到另一个php页面 - Pass a php variable from one page to another php page 如何使用HTML表单将JavaScript值传递到另一个PHP页面? - How can I pass JavaScript values to another PHP page using an HTML form? 使用ajax代码将php变量从一页传递到另一页 - pass a php variable from one page to another page with ajax code 将html页面中的一个php页面从一个网站调用到另一个 - Calling one php page in html page from one website to another PHP:如何在使用提交按钮将用户定向到另一页的同时,将隐藏变量传递给一页? - PHP: how can I pass a hidden variable to one page while using a submit button to direct the user to another page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM