복붙노트

PHP, MySQL 오류 : 열 개수가 행 1의 값 개수와 일치하지 않습니다.

PHP

PHP, MySQL 오류 : 열 개수가 행 1의 값 개수와 일치하지 않습니다.

이 오류가 발생합니다.

열 개수가 행 1의 값 개수와 일치하지 않습니다.

다음 코드에서 :

$name = $_GET['name'];
$description = $_GET['description'];
$shortDescription = $_GET['shortDescription'];
$ingredients = $_GET['ingredients'];
$method = $_GET['method'];
//$image = $_GET['image'];
$username = $_GET['username'];
$length = $_GET['length'];
$dateAdded = uk_date();
$conn = mysql_connect('localhost', 'dbname', 'pass');
mysql_select_db('dbname');
$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));

    $result = mysql_query($query) or die(mysql_error());

오류는 무엇을 의미합니까?

해결법

  1. ==============================

    1.나열된 9 개의 필드가 있지만 8 개의 값만 있습니다. 메소드를 추가하십시오.

    나열된 9 개의 필드가 있지만 8 개의 값만 있습니다. 메소드를 추가하십시오.

  2. ==============================

    2.삽입 쿼리의 열 매개 변수 수는 9이지만 8 개의 값만 제공했습니다.

    삽입 쿼리의 열 매개 변수 수는 9이지만 8 개의 값만 제공했습니다.

    INSERT INTO dbname (id, Name, Description, shortDescription, Ingredients, Method, Length, dateAdded, Username) VALUES ('', '%s', '%s', '%s', '%s', '%s', '%s', '%s')
    

    자동 생성 되었기 때문에 검색어에 'id'매개 변수를 생략해야합니다 (어쨌든 있어야 함).

    INSERT INTO dbname (Name, Description, shortDescription, Ingredients, Method, Length, dateAdded, Username) VALUES ('', '%s', '%s', '%s', '%s', '%s', '%s', '%s')
    

    행운을 빕니다!

  3. ==============================

    3.귀하의 질의에는 8 개 또는 심지어 9 개의 변수가 있습니다. 값, 이러한 것들 ---> ','% s ​​','% s ​​','% s ​​','% s ​​','% s ​​','% s ​​','% s ​​' s ') ", 합계 7 개만 있으면 변수의 수는 값과 같아야합니다.

    귀하의 질의에는 8 개 또는 심지어 9 개의 변수가 있습니다. 값, 이러한 것들 ---> ','% s ​​','% s ​​','% s ​​','% s ​​','% s ​​','% s ​​','% s ​​' s ') ", 합계 7 개만 있으면 변수의 수는 값과 같아야합니다.

    나는 같은 문제가 있었지만 그것을 알아 냈다. 잘하면 그것은 또한 당신을 위해 작동합니다.

  4. from https://stackoverflow.com/questions/5931900/php-mysql-error-column-count-doesnt-match-value-count-at-row-1 by cc-by-sa and MIT license