gpt4 book ai didi

php - 无法获取 $_POST 值(php、html)

转载 作者:行者123 更新时间:2023-12-02 22:10:34 28 4
gpt4 key购买 nike

我无法获取从我的 php 文件上的 html 表单发送的 $_POST['name'] 值。我见过很多类似的问题,但没有任何帮助。我有很多包含,所以我认为这是一个范围问题,但我无法弄清楚。

索引.php

print_r($_POST); //Returns nothing, tried other ways too

//lot's of variables being defined

include 'sql_data_handlers.php';
//instantiating some things

sql_data_handlers.php

//some functions retrieving data from sql db and finally:
include($DOCUMENT_ROOT . "page.html");

页面.html

//html stuff
<?php
//Some conditions
include($DOCUMENT_ROOT . "comment_form.html");
?>

comment_form.html

<form action="index.php" name="comment_form" id="comment_form" method="post">
<input type="text" name="name" value="Anonymous" required><br>
//lot's of inputs
<input type="submit">
</form>

我曾经有 action="send_comment.php" 但我意识到它可以变成一个函数所以我 ctrl+c 并将 send_comments.php 改编成sql_data_handlers.php 上的函数。问题是,现在我无法在 index.php 上获取 $_POST 值以用于 sql_data_handlers.php 上的函数(其中包含在 index.php 中)。

如果可能的话,我会使用 action="my_php_function_from_data_handlers.php($args)",但我想不可能。顺便说一句,我已经尝试过 action=""。这可能看起来很乱,但这样我只需要一个 .html 用于网站布局,页面在 sql 上,.php 文件完成所有工作。

所有文件的完整来源(相当大,仍在处理中): http://pastebin.com/2nRuCpNx

最佳答案

确保您没有任何类型的重定向,因为您正在使用 index.php 来保存数据,您可能正在重新加载页面以显示更新的评论。如果你正在重新加载,$_POST 上将没有数据被 print_r() 打印。

关于php - 无法获取 $_POST 值(php、html),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15380973/

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