无法获取$ _POST值(php,html) [英] Can't get $_POST values (php, html)

查看:174
本文介绍了无法获取$ _POST值(php,html)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I can't get the $_POST['name'] values sent from an html form on my php file. I've seen lots of similar questions but nothing helped. I have lot's of includes so I believe it's a scope issue, but I can't figure it out.

index.php

index.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

sql_data_handlers.php

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

page.html

page.html

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

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 中)。

I used to have action="send_comment.php" but I realized it could be turned into a function so I ctrl+c and adapted send_comments.php to a function on sql_data_handlers.php. The problem is, now I can't get the $_POST values on index.php to use in the function on sql_data_handlers.php (which is included in index.php).

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

I would use action="my_php_function_from_data_handlers.php($args)" if it was possible, but I guess it isn't. btw, I already tried action="". This may seem pretty messy but this way I only need one .html for the site layout, pages are on the sql and the .php files do all the job.

完成所有文件的来源(相当大,仍在使用它):
http://pastebin.com/2nRuCpNx

Complete source of all files (pretty big, still working on it): http://pastebin.com/2nRuCpNx

推荐答案

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

Make sure you don't have any kind of redirects, since you're using index.php to save data, you're probably reloading the page to show the updated comments. And if you're reloading, there'll be no data on $_POST to be printed by print_r().

这篇关于无法获取$ _POST值(php,html)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆