[Solved] mysql_fetch_assoc(): 6 is not a valid MySQL result resource [duplicate]


Make sure to add checks when making your connection as well as after the query

    $server="127.0.0.1";
    $username="root";
    $password = '';
    $database="test";


mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());

$TableName = "opportunities";
$Opportunities = array();
$SQLString = "SELECT opportunity_ID, company, city, " . 
 "start_date, end_date, position, description" . " FROM $TableName;";       
$QueryResult = mysql_query($SQLString);

if(mysql_error()) {
    die(mysql_error();
}

if($QueryResult) {

        while($Row = mysql_fetch_assoc($QueryResult)) 
        {
            $Opportunities[] = $Row;
        }
            mysql_free_result($QueryResult);
}

mysql_close();

Also, you were freeing the result $QueryResult inside the loop, so the next iteration would have no resource to grab data from.

1

solved mysql_fetch_assoc(): 6 is not a valid MySQL result resource [duplicate]