2013-03-15 19 views
26

Ho qualche problema a verificare se un ID utente FB esiste già nel mio db (se non lo è dovrebbe quindi accettare l'utente come nuovo e solo caricare l'app canvas). Ho eseguito sul mio server di hosting e non c'era nessun problema, ma sul mio localhost mi da seguente errore:mysqli_fetch_array() si aspetta che il parametro 1 sia mysqli_result, booleano dato in

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

Ecco il mio codice:

<? 
$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; 
} 

ho letto che ha qualcosa a fare con la mia query è sbagliato, ma ha funzionato sul mio provider di hosting in modo che non può essere!

+2

è necessario aggiungere la gestione degli errori per le vostre domande in modo da poter scoprire esattamente il motivo per cui sta venendo a mancare. Hai anche una significativa vulnerabilità di SQL injection. –

+1

Per favore, ** per favore ** usa la funzione di istruzione preparata 'mysqli' su [correttamente sfugge alle tue query SQL] (http://bobby-tables.com/php). – tadman

risposta

63

Questa query ha esito negativo e restituisce false.

mettere questo dopo mysqli_query() per vedere che cosa sta succedendo.

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

per ulteriori informazioni:

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

Problemi correlati