【问题标题】:keeping form values after POST as a paramter of python file在 POST 之后保留表单值作为 python 文件的参数
【发布时间】:2016-10-23 15:53:39
【问题描述】:

我有一个表单,提交到一个php文件并将值插入DB(MySql)。成功将值插入DB后,我想将此参数表单的值用作另一个php文件中的python文件当我提交时。

文件register.php -> 文件description.php(按钮开始)-> 文件exucuter.php(执行pythonfile)

【问题讨论】:

    标签: php python mysql forms


    【解决方案1】:

    如果您在进行数据库插入后,不要重定向到 exucuter.php,如果您

    include 'exucuter.php';  // (assuming they are in the same directory)
    

    description.php 中,在 DB 完成工作后,您应该能够直接使用 exucuter.php$_POST 中的值。这样您就不必担心将它们存储在某个地方或在两个脚本之间传输它们。


    如果您的第二个脚本 (description.php) 在第三个脚本 (exucuter.php) 运行之前需要一些额外的用户交互,那么您不能只包含 exucuter.php,并且您确实需要一种方法来保留第一个脚本中的值。有不同的方法可以做到这一点:将它们存储在会话或文件或数据库中,将它们放在 description.php 中表单操作的查询字符串中,或​​者将它们作为隐藏输入。这是一个使用隐藏输入的示例:

    register.php

    <form action="description.php" method="POST">
        <label for="x">X: </label><input type="text" name="x" id="x">
        <input type="submit" value="Register">
    </form>
    

    description.php

    <?php if (isset($_POST['x'])) {  /* Do your DB insert */; } ?>
    <form action="exucuter.php" method="POST">
    
        <!--Use a hidden input to pass the value given in register.php-->
        <input type="hidden" name="x" value="<?php isset($_POST['x']) ? $_POST['x'] : ''; ?>">
    
        <label for="y">Y: </label><input type="text" name="y" id="y">
        <input type="submit" value="Execute">
    </form>
    

    exucuter.php

    <?php 
    if (isset($_POST['x']) && isset($_POST['y'])) {
        // execute your python program
    }
    

    【讨论】:

    • 我想使用 register.php 中包含的值和 description.php 中包含的值作为 python 文件的参数。通过单击 description.php 中的按钮知道将执行 python 文件。
    • @sonia 很抱歉我一开始误解了。我编辑了答案。
    • 你能告诉我在会话中存储它们的方法吗?
    猜你喜欢
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-25
    • 2010-12-05
    • 1970-01-01
    相关资源
    最近更新 更多