PHP、MySQL 错误:列计数与第 1 行的值计数不匹配已解决
遇到错误“列计数不匹配” t match value count at row 1”,它表示数据库表中的列数与 INSERT 语句中提供的值数之间存在差异。
在提供的代码片段中:
<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>
您在 INSERT 语句中指定了 9 列,但只提供了 8 个值。具体来说,您缺少“方法”列的值。
要解决此问题,您应该将方法值添加到 INSERT 语句中:
<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), mysql_real_escape_string($length), mysql_real_escape_string($dateAdded), mysql_real_escape_string($username) ); // ...</code>
以上是为什么我的 PHP MySQL INSERT 语句中出现'列计数与第 1 行的值计数不匹配”错误?的详细内容。更多信息请关注PHP中文网其他相关文章!