>  기사  >  백엔드 개발  >  PHP MySQL에서 \"열 개수가 행 1의 값 개수와 일치하지 않습니다\" 오류가 발생하는 이유는 무엇입니까?

PHP MySQL에서 \"열 개수가 행 1의 값 개수와 일치하지 않습니다\" 오류가 발생하는 이유는 무엇입니까?

Barbara Streisand
Barbara Streisand원래의
2024-10-27 11:06:30658검색

Why Am I Getting the

PHP MySQL의 "열 개수가 행 1의 값 개수와 일치하지 않습니다" 오류 해결

이 오류는 데이터베이스 테이블이 테이블의 열 수와 일치하지 않습니다.

제공한 코드에서 9개의 열이 있는 테이블에 8개의 값을 삽입하려고 합니다.

<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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.