0

The function below will be used to input a Facebook access token into a database. The user id will already have an associated record so the "acc_tok" field just needs to be updated.

For some reason even though the $_result value holds "1" and the function echoes out "Successful!", a warning is appearing that says:

"Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given". Does anyone know why it appears that the query was successful but is only returning a boolean and not something the mysql_fetch_array can work with? Thanks for reading

function setUserAccessToken($_uid, $_accTok){
        $sql = "UPDATE `user_core` SET `acc_tok`=$_accTok WHERE `id` = $_uid";
        $_result = mysql_query($sql) or die($sql."<br/><br/>".mysql_error());
        echo $_result;
        if ($_result) {
        echo ("Successful!");
            $_resultArray = mysql_fetch_array($_result);
            print_r($_resultArray);
        } else {
            echo ("Failed!");
        }
}
2
  • 1
    It may not help answer your question, but you should stop using mysql_* functions. They're being deprecated. Instead use PDO (supported as of PHP 5.1) or mysqli (supported as of PHP 4.1). If you're not sure which one to use, read this article. Commented Aug 16, 2012 at 16:54
  • What does var_dump($_result) give you? Commented Aug 16, 2012 at 16:55

1 Answer 1

6

You're doing an UPDATE query, there are no rows to fetch from the result, hence a boolean value from mysql_query() and not a resource.

From the manual:

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.