【问题标题】:How to get php variable from an action form and use it in the form thats activating the action如何从动作表单中获取 php 变量并在激活动作的表单中使用它
【发布时间】:2017-04-06 12:03:37
【问题描述】:

我在这里有两个文件作为测试第一个文件在下面,当我单击提交时假设在下一页上执行操作,但我想知道如何从操作 php 中检索 $life 变量文件并将其放入普通的html文件中

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
<form class="" action="../logic/profileAction.php" method="post">
<label for=""></label>
  <button type="submit" name="button">Submit</button>
</form>
  </body>
</html>

第二个文件是php文件:

<?php
$life ="Yo";
 ?>

【问题讨论】:

  • 您的问题不清楚。你想在提交后在第一个文件中显示 $life 变量吗?
  • 你的问题有点笼统,请把完整的代码贴出来
  • 您的表单不会向 profileAction.php 发送任何数据。那么你希望成为什么样的人呢?
  • 如果你想显示 $life 变量然后在第一个文件中包含第二个文件
  • 你为什么不在html文件中简单地$life?!你想达到什么目的?

标签: php html forms


【解决方案1】:

检查此代码。您需要在服务器中运行此代码

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
  <?php
  include_once 'edit.php';
  echo $life;
  ?>

<form class="" action="../logic/profileAction.php" method="post">
<label for=""></label>
  <button type="submit" name="button">Submit</button>
</form>
  </body>
</html>

这是你的 include edit.php

<?php
$life = 'Ok';
?>

那么当您运行此代码时,您的第一个文件显示正常

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多