douyong4623 2015-03-12 23:45
浏览 157

如何在PHP文件中触发PHP文件的执行

So I have an HTML file that is a basic form. Say

<form method="POST" action="test1.php">
        Name: <input type="text" name="name" id="name" />
        <input type="submit" value="Submit" />
    </form>

Now I have that execute my test1.php file which goes as follows:

<?php
$name = $_POST['name'];
?>

So all it is doing is getting the value from the HTML form. Now I have a second PHP file test2.php that needs to get the value from the first test1.php file $name and output it via an echo statement.

I'm new to PHP and am fine with using one PHP file to output values from an HTML form, but I don't know how to approach a second one.

I'm aware that you can use the include statement to carry over the variables and their values, but it didn't seem to work in my instance. I'm almost positive the issue is that I don't have test2.php actually being executed. And I don't know how to approach that. Any help is appreciated.

EDIT: This is all I want test2.php to do. $name has to be the same value as retrieved from the HTML form in test1.php

    <?php
    echo $name;
    ?>
  • 写回答

3条回答 默认 最新

  • dongnuo2879 2015-03-12 23:49
    关注

    Just use include your file test2.php inside test1.php:

    <?php
        $name = $_POST['name'];
        include('test2.php');
    ?>
    

    Whenever you include a file using either include() or require(), the file always gets "executed", so maybe there's something else wrong in you code.

    EDIT

    test1.php:

    <?php
        $name = $_POST['name'];
        include('test2.php');
    ?>
    

    test2.php:

    <?php
        echo $name;
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀