當您嘗試插入的值的數量超過此錯誤時,會發生此錯誤資料庫表與表中的列數不符。
在您提供的程式碼中,您嘗試將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中文網其他相關文章!