You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP表单提交后无法输出输入数据问题求助

Fix: Form Submission Data Not Displaying in PHP

Hey there! Let's work through why your form isn't showing the data you submit when you click the submit button. I noticed a few critical issues in your PHP code that are causing this problem:

1. Function Definition Order is Wrong

You’re calling the check_input() function at the very top of your PHP file, but you don’t define that function until the end of the file. PHP runs code from top to bottom—so when it hits $yourname = check_input($_POST['yourname']);, it has no idea what check_input is yet! This throws a fatal error that stops the rest of your code from running, which is why you don’t see any data.

Fix: Move the check_input function to the start of your PHP file, before you try to use it.

2. No Check for Existing POST Data

If someone visits abiform.php directly (without submitting the form), the $_POST array won’t have any of your form’s keys. This will trigger "Undefined index" warnings, which can break your page’s output. We need to check if those keys exist before trying to use them.

3. Enable Error Reporting (For Debugging)

Turning on PHP’s error reporting during development will help you spot issues like these quickly. Add a few lines at the top of your PHP file to enable this.

Updated Working PHP Code

<?php
// Turn on error reporting (only for development—disable in production!)
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Define the sanitization function FIRST
function check_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

// Check if POST data exists before sanitizing
$yourname = isset($_POST['yourname']) ? check_input($_POST['yourname']) : '';
$email = isset($_POST['email']) ? check_input($_POST['email']) : '';
$urgency = isset($_POST['urgency']) ? check_input($_POST['urgency']) : '';
$existingissue = isset($_POST['existingissue']) ? check_input($_POST['existingissue']) : '';
$hours = isset($_POST['hours']) ? check_input($_POST['hours']) : '';
$description = isset($_POST['description']) ? check_input($_POST['description']) : '';
$outcome = isset($_POST['outcome']) ? check_input($_POST['outcome']) : '';
?>
<html>
<body>
Company Name: <?php echo $yourname; ?><br />
<br />
Company e-mail: <?php echo $email; ?><br />
<br />
Urgency: <?php echo $urgency; ?><br />
<br />
Existing Feature or Issue? <?php echo $existingissue; ?><br />
<br />
Max Hours Willing to Spend on Issue: <?php echo $hours; ?><br />
<br />
Issue Description:<br />
<?php echo $description; ?>
<br />
Expected Outcome:<br />
<?php echo $outcome; ?>
</body>
</html>

Extra Tips to Improve Your Form

  • Your HTML form’s name attributes are all set correctly—great job there!
  • Add required to mandatory fields to enforce user input on the front end, like: <input type="text" name="yourname" required />
  • Use type="email" for the email field to get basic front-end validation: <input type="email" name="email" required />

After making these changes, your form should display the submitted data correctly. If you still run into issues, check Apache’s error log (usually located in apache/logs/error.log) for any additional error messages that might point to other problems.

内容的提问来源于stack exchange,提问作者K. Man

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:40:47