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

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

Barbara Streisand
Barbara Streisand원래의
2024-10-26 18:57:30984검색

Why Am I Getting

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

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