gpt4 book ai didi

php - 将 POST 后的表单值保留为 python 文件的参数

转载 作者:行者123 更新时间:2023-11-29 11:27:30 25 4
gpt4 key购买 nike

我有一个表单,提交的表单会转到一个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中,数据库完成工作后,您应该能够直接使用exucuter.php$_POST中的值>。这样您就不必担心将它们存储在某个地方或在两个脚本之间传输它们。

<小时/>

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

注册.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>

描述.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
}

关于php - 将 POST 后的表单值保留为 python 文件的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37955610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com