php
  • mysql
  • 2012-07-13 4 views 0 likes 
    0

    이 코드는 올바르게 작동하고 모든 올바른 정보를 데이터베이스에 입력하지만 오류 검사는 오류를 반환합니다. 나는 에러 체크를 제거 할 수 있지만, 나중에 나를 잡으러 나 다시 온다 일부 악몽을 만드는 두려워 나는 근본적인 문제 누락 것을 :mysql_query는 작동하지만 오류 검사는 오류를 반환합니다.

    $sql5a = mysql_query("SELECT id FROM categories WHERE category='$category'"); 
         $categoryresult = mysql_fetch_array($sql5a); 
         $oldcategoryid = $categoryresult['id']; 
         $sql6a = "INSERT INTO lookupcategory SET 
         fbid='$fbid2', 
         categoryid='$oldcategoryid'"; 
          if (@mysql_query($sql5b)) { 
               echo('sql5b updated successfully<br>'); 
              } else { 
               echo('Error: sql5b not updated<br>'.mysql_error()); 
             } 
              if (@mysql_query($sql6b)) { 
               echo('sql6b updated successfully<br>'); 
              } else { 
               echo('Error: sql6b not updated<br>'.mysql_error()); 
             } 
    

    이 출력은 : "오류 : sql5b이 를 업데이트하지를 SQL 구문에 오류가 있습니다. MySQL 서버 버전에 해당하는 설명서에서 1 행의 'Resource id # 7'근처에서 " "sql6b가 성공적으로 업데이트 된 것을 확인하십시오.

    데이터베이스 모든 항목이 정확합니다. sql5a가 작동하지 않으면 sql6b가 작동하지 않아 오류에 대한 혼란이있었습니다.

    샘플 카테고리 것이다/레저 범주 원래 형태의 반응에서 생성 된 여행 : $ 카테고리를 htmlentities = ($ fbdetail [ '장르', ENT_QUOTES); 그리고 데이터베이스에 성공적으로 입력되었습니다. AUTO_INCREMENT를 사용하여 ID 번호가 지정되었습니다.

    +0

    INSERT 구문이 잘못되었습니다. 또한 오류로부터 판단 할 때 쿼리 문자열에 리소스 변수를 사용하고 있습니다. – lafor

    답변

    0

    당신은 변수 $sql5a에 쿼리를 할당하지만, @mysql_query($sql5b)를 호출합니다. $sql5b이 존재하지 않습니다 (적어도이 샘플에서). $sql6a과 동일 ...

    VALUES없이 INSERT 구문을 사용할 수 있지만, INTO 키워드는 필요하지 않습니다. 당신이에서 $fbid2 또는 $category를 얻을 곳이이 코드 조각에없는 때문에

    $sql5a = mysql_query("SELECT id FROM categories WHERE category='$category'"); 
    if ($res5a = @mysql_query($sql5a)) { // first execute query and store resource in variable 
        echo('sql5a selected successfully<br>'); 
    } else { 
        echo('Error: sql5a failed<br>'.mysql_error()); 
    } 
    $categoryresult = mysql_fetch_array($res5a); // fetch array passing the RESOURCE var, NOT query string 
    $oldcategoryid = $categoryresult['id']; 
    $sql6a = "INSERT lookupcategory SET 
    fbid='$fbid2', 
    categoryid='$oldcategoryid'"; 
    
    if (@mysql_query($sql6a)) { 
        echo('sql6a inserted successfully<br>'); 
    } else { 
        echo('Error: sql6a failed<br>'.mysql_error()); 
    } 
    

    는 나는 모른다.

    0

    삽입하는 구문은 다음과 같습니다 특정 경우

    INSERT INTO table(col1, col2 ...) VALUES(val1, val2 ...) 
    

    :

    $sql6a = "INSERT INTO table(fbid, categoryid) VALUES('{$fbid2}','{$oldcategoryid}')" 
    
    +0

    또한 VALUES ('val1', 'val2')는 테이블에 'INSERT INTO'테이블 ('col1','col2')과 같이 error = values – Yang

    관련 문제