2013-03-15 2 views
26

으로 지정합니다. FB User_id가 이미 내 db에 있는지 확인하는 데 문제가 있습니다 (그렇지 않으면 사용자를 새로운 것으로 받아 들여야합니다. 캔버스 앱을로드하십시오.) 내 호스팅 서버에 그것을 실행하고 아무 문제가 없었다,하지만 내 로컬 호스트에 나에게 다음과 같은 오류 제공 : 내가 읽은mysqli_fetch_array()는 매개 변수 1이 mysqli_result가 될 것으로 예상하고, 부울은

<? 
$fb_id = $user_profile['id']; 
$locale = $user_profile['locale']; 

if ($locale == "nl_NL") { 
    //Checking User Data @ WT-Database 
    $check1_task = "SELECT * FROM `users` WHERE `fb_id` = " . $fb_id . " LIMIT 0, 30 "; 
    $check1_res = mysqli_query($con, $check1_task); 
    $checken2 = mysqli_fetch_array($check1_res); 
    print $checken2; 
    //If User does not exist @ WT-Database -> insert 
    if (!($checken2)) { 
     $add = "INSERT INTO users (fb_id, full_name, first_name, last_name, email) VALUES ('$fb_id', '$full_name', '$first_name', '$last_name', '$email')"; 
     mysqli_query($con, $add); 
    } 
    //Double-check, User won't be able to load app on failure inserting to database 
    if (!($checken2)) { 
     echo "Excuse us " . $first_name . ". Something went terribly wrong! Please try again later!"; 
     exit; 
    } 
} else { 
    include ('sorrylocale.html'); 
    exit; 
} 

이 뭔가를 가지고 : 여기

mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in 

내 코드의를 내 쿼리가 틀리면 어떻게됩니까?하지만 내 호스팅 제공 업체에서 일 했으니까요.

+2

당신은 당신이 실패하는 이유를 정확하게 알 수 있도록 쿼리에 오류 처리를 추가해야합니다. 또한 중요한 SQL 주입 취약점이 있습니다. –

+1

** mysqli' prepared statement 기능을 사용하여 [SQL 쿼리를 올바르게 이스케이프합니다.] (http://bobby-tables.com/php). – tadman

답변

63

해당 쿼리가 실패하고 false을 반환합니다.

mysqli_query() 뒤에 무슨 일이 일어나는지 살펴 봅니다. 자세한 내용은

if (!$check1_res) { 
    printf("Error: %s\n", mysqli_error($con)); 
    exit(); 
} 

는 :

http://www.php.net/manual/en/mysqli.error.php

관련 문제