当您尝试插入的值的数量超过此错误时,会发生此错误数据库表与表中的列数不匹配。
在您提供的代码中,您尝试将 8 个值插入具有 9 列的表中:
<code class="php">$query = sprintf("INSERT INTO dbname (id, Name, Description, shortDescription, Ingredients, Method, Length, dateAdded, Username) VALUES ('', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", mysql_real_escape_string($name), mysql_real_escape_string($description), mysql_real_escape_string($shortDescription), mysql_real_escape_string($ingredients), //mysql_real_escape_string($image), mysql_real_escape_string($length), mysql_real_escape_string($dateAdded), mysql_real_escape_string($username));</code>
要解决错误,您需要添加“方法”列的缺失值。以下是修改后的代码:
<code class="php">$query = sprintf("INSERT INTO dbname (id, Name, Description, shortDescription, Ingredients, Method, Length, dateAdded, Username) VALUES ('', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", mysql_real_escape_string($name), mysql_real_escape_string($description), mysql_real_escape_string($shortDescription), mysql_real_escape_string($ingredients), mysql_real_escape_string($method), // Added the Method value mysql_real_escape_string($length), mysql_real_escape_string($dateAdded), mysql_real_escape_string($username));</code>
进行此更改后,您不应再遇到“列计数与第 1 行的值计数不匹配”错误。
以上是为什么我在 PHP MySQL 中收到'列计数与第 1 行的值计数不匹配”错误?的详细内容。更多信息请关注PHP中文网其他相关文章!