PHP $_POST获取值失败,页面返回空结果求助
Hey there, I totally get how frustrating it is when $_POST just refuses to work—you’ve tried all the usual fixes and nothing sticks. Let’s break this down step by step, starting with the most likely culprits:
First, Check Your Form’s Submit Button
Looking at your code snippet, it cuts off at <input type="submi...—did you forget to add the name="submit" attribute to your submit button? If your button looks like this:
<input type="submit" value="Submit">
Then isset($_POST['submit']) will always return false, because the button has no name. Fix it by adding the name attribute:
<input type="submit" name="submit" value="Submit">
Debug with Raw POST Data
Stop relying on the submit check for now—add this at the very top of inbox.php to see exactly what’s coming through:
<?php var_dump($_POST); echo "<br>Request Method: " . $_SERVER['REQUEST_METHOD']; ?>
If $_POST is still empty but REQUEST_METHOD says POST, that means the server is receiving a POST request but isn’t parsing the data correctly.
Check PHP.ini Configuration
Two settings can cause PHP to discard POST data entirely:
post_max_size: If your textarea content is longer than this value (default is often 8M), PHP will throw away the POST data. Open your php.ini, find this line, and increase it (e.g.,post_max_size = 10M).upload_max_filesize: While this is for file uploads, if you’re accidentally usingmultipart/form-dataenctype without files, it might cause issues—stick to the defaultapplication/x-www-form-urlencodedfor text-only forms.
Rule Out Server/Environment Issues
Try a minimal test case to see if the problem is with your code or the environment:
Create test.html:
<form action="test.php" method="post"> <input type="text" name="test_data" value="Hello from POST"> <input type="submit" name="send" value="Submit"> </form>
Create test.php:
<?php var_dump($_POST); ?>
If this test works, the issue is in your original code (check for nested forms, JavaScript modifying the submit action, or typos in field names). If it still returns empty, check:
- Your server’s rewrite rules (
.htaccessfiles can sometimes mangle POST requests—try renaming it temporarily). - Browser extensions or caching: Try incognito mode to rule out cached GET requests or interfering extensions.
Final Checks
- Make sure your form isn’t using
method="get"by mistake (easy typo!). - Ensure there are no syntax errors in your PHP code that might be stopping execution before you can access $_POST.
内容的提问来源于stack exchange,提问作者M7md0136466

