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

反馈提交报错:Doesn't match number of tokens 问题排查求助

Fixing "Doesn't match number of tokens" Error in Your Feedback Form

Hey Andre, let's break down what's causing this error and fix it quickly!

The Root Cause

The error "Doesn't match number of tokens" happens because your SQL INSERT statement has a mismatch between the number of columns you're inserting into and the number of placeholder tokens (?) you've defined.

Looking at your insert-message.php code:

$insert_query = "INSERT INTO tbl_feedback (employee_id, full_name, email, website, message) VALUES (?, ?, ?, ?)";

You're targeting 5 columns (employee_id, full_name, email, website, message) but only providing 4 placeholder tokens in VALUES. When you call execute() with 5 values ($employee_id, $full_name, $email, $website, $message), PDO throws an error because the count doesn't line up.

The Fix

Update your INSERT query to include 5 placeholder tokens to match the 5 columns:

$insert_query = "INSERT INTO tbl_feedback (employee_id, full_name, email, website, message) VALUES (?, ?, ?, ?, ?)";

Bonus Cleanup Tips

While you're at it, here are a couple of small improvements to make your code more robust:

  • Remove redundant curly braces: You have an extra { right after $message = ($_POST['message']); that doesn't serve any purpose and can cause confusion.
  • Add try-catch for better error handling: Wrapping your PDO code in a try-catch block will let you see detailed error messages if something goes wrong, instead of just relying on ERRMODE_EXCEPTION:
    try {
        $database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $insert_query = "INSERT INTO tbl_feedback (employee_id, full_name, email, website, message) VALUES (?, ?, ?, ?, ?)";
        $insert = $database->prepare($insert_query);
        $insert->execute(array($employee_id, $full_name, $email, $website, $message));
        echo "<script>alert('Successfully sent!'); window.location='feedback.php'</script>";
    } catch(PDOException $e) {
        echo "Error: " . $e->getMessage();
    }
    
  • Clean up duplicate autofocus: Your form has two fields with autofocus="autofocus" – only one field can have autofocus at a time, so you can remove one of those to avoid unexpected behavior.

That should resolve the token mismatch error and make your feedback form work as expected!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 08:19:34