【发布时间】:2016-10-23 15:53:39
【问题描述】:
我有一个表单,提交到一个php文件并将值插入DB(MySql)。成功将值插入DB后,我想将此参数表单的值用作另一个php文件中的python文件当我提交时。
文件register.php -> 文件description.php(按钮开始)-> 文件exucuter.php(执行pythonfile)
【问题讨论】:
我有一个表单,提交到一个php文件并将值插入DB(MySql)。成功将值插入DB后,我想将此参数表单的值用作另一个php文件中的python文件当我提交时。
文件register.php -> 文件description.php(按钮开始)-> 文件exucuter.php(执行pythonfile)
【问题讨论】:
如果您在进行数据库插入后,不要重定向到 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
}
【讨论】: