警告:mysql_fetch_assoc():提供的参数不是有效的MySQL [重复]

I met some trouble with that error

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in In fact for not having global variables I put all my query in functions.

My queries are ok, no mistakes in the fields name of where ever else.

The trouble is that on local all is fine working, when I put it online, it does not workd, and everywhere it return me some mistakes

for the home I have this mistakes:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /web/teamfrancestron/www/lib_php/strongman.php on line 75

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /web/teamfrancestron/www/lib_php/strongman.php on line 90

My user have all privilege in the database,

here is the code I use : here is for the first mistake

function fetchAccueil() {
    $sql = "SELECT 
                    `content`, `date_maj`, `id_maj`, `titre` 
            FROM `stg_man_home` 
            WHERE 
                    `id` = '1'";
    $result = mysql_query($sql);
    return mysql_fetch_assoc($result);
}

And there for the other query

/** * Fonction qui va chercher l'identité d'une personne. * @param type $id * @return type */

function fetchIdentity($id) {
    $input_id = mysql_real_escape_string($id);
    $query = "SELECT 
                        `nom`, `prenom`
              FROM `stg_man_users`
              WHERE `id` = '{$input_id}'";
    $result = mysql_query($query);
    return mysql_fetch_assoc($result);
}

I realy do not see any mistakes on names fileds, I'm sure that my queries are valid ressources. (works on local but not on the server). Im on php 5.4

On other pages I have still the same mistakes

Anykind of help will be much appreciated.

</div>

Check the return value of mysql_query. It can be a result set, but also just the value false. Change your query to

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

and you will see the problem at once.

As a sidenote: consider switching to mysqli or PDO, because mysql_* functions are deprecated by now.

The error message means running your query failed.

The simplest way to test the query is open up a phpmyadmin or mysql console (with the same user), and run this exact query.

You say

WHERE id = '1'

Do this instead (drop the single quotations):

WHERE id = 1

So that you request a match against an integer but not a string.