Can't get $_POST values (php, html)

Deadly 提交于 2019-12-24 00:57:51

问题


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

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");

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

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

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.

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


回答1:


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().




回答2:


Try changing the value of the input name attribute to something different from "name". Some configurations have issues with that, especially wordpress.

for example:

<input type="text" name="user_name" value="Anonymous" required>



回答3:


would you mind to change your

.html filename to .php filename

your codes runs in my local server because sometimes the difference lies in how your web server is configured.

when running in an web server it is best to use .php in your files



来源:https://stackoverflow.com/questions/15380973/cant-get-post-values-php-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!