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

增删改表单提示添加成功但数据未写入MySQL问题排查

Troubleshooting: Data Not Saving to MySQL Despite Success Message

Let's walk through why your form's "Add" action is showing a success message but not actually storing data in your user table, plus address your MySQLi vs. MySQL concern.

First: Critical Missing Piece – Where is add.php?

Your add.html form submits to add.php, but you didn't include this file in your code snippet. This is almost certainly the biggest issue right now! If add.php doesn't exist or isn't properly handling the INSERT logic, the success message you're seeing is either hardcoded somewhere (without actual database interaction) or coming from a broken script.

Example Working add.php (With Error Handling)

Create this file if it doesn't exist, and adjust it to match your setup:

<?php
include_once("config.php");

if(isset($_POST['Submit'])) {
    // Grab form data
    $steamUE = $_POST['steamUE'];
    $steamPW = $_POST['steamPW'];
    $steamGC = $_POST['steamGC'];

    // Basic empty field check
    if(empty($steamUE) || empty($steamPW) || empty($steamGC)) {
        echo "<font color='red'>All fields are required!</font><br>";
        echo "<a href='add.html'>Go back</a>";
        exit();
    }

    // Insert query
    $insertQuery = "INSERT INTO `user` (steamUE, steamPW, steamGC) VALUES ('$steamUE', '$steamPW', '$steamGC')";
    $result = mysqli_query($mysqli, $insertQuery);

    // Check if insert succeeded
    if($result) {
        echo "Data added successfully.";
        // Redirect to homepage after 2 seconds
        header("Refresh: 2; url=index.php");
        exit();
    } else {
        // Show actual error to debug
        echo "Failed to add data: " . mysqli_error($mysqli);
    }
}
?>

Check If Your Host Supports MySQLi

To confirm your host's support for MySQLi (and rule out your initial suspicion), create a simple test file named mysqli-test.php with this code:

<?php
if (extension_loaded('mysqli') && function_exists('mysqli_connect')) {
    echo "✅ MySQLi is supported on your host!";
} else {
    echo "❌ Only the deprecated MySQL extension is available (not recommended for use).";
}
?>

Upload it to your host and visit it in your browser. If MySQLi is supported, move on to other checks. If not, you'd need to replace all mysqli_* functions with their old mysql_* equivalents (though this is strongly discouraged, as MySQL is deprecated and insecure).

Other Common Issues to Debug

  1. Verify Database Connection (config.php)
    Double-check that your config.php uses mysqli_connect (not mysql_connect) and has the correct database credentials:

    <?php
    $mysqli = mysqli_connect("localhost", "your_username", "your_password", "your_database");
    // Check connection
    if (mysqli_connect_errno()) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
        exit();
    }
    ?>
    
  2. Confirm Table & Field Names Match
    Make sure your user table actually has the fields steamUE, steamPW, and steamGC (typos here are super common!). You can verify this directly in phpMyAdmin by checking the table structure.

  3. Check Database User Permissions
    Ensure the database user you're using has INSERT, SELECT, UPDATE, and DELETE permissions for the user table. You can adjust this in phpMyAdmin under the "Privileges" tab.

  4. Fix Typo in edit.php
    You have a duplicate label in your edit form – change the second "Steam Username" to "Steam Password":

    <tr>
        <td>Steam Password</td> <!-- Fixed from "Steam Username" -->
        <td><input type="text" name="steamPW" value="<?php echo $steamPW;?>"></td>
    </tr>
    

Final Steps

  1. Add the add.php script above (or fix your existing one) with proper error handling.
  2. Run the MySQLi support test to confirm your host's capabilities.
  3. Refresh phpMyAdmin after testing the "Add" action (sometimes cached views don't show new data immediately).

内容的提问来源于stack exchange,提问作者unnamedUser

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 04:14:54