Mysql_Fetch_Assoc(): Supplied Argument Is Not a Valid MySQL Result Resource in PHP

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result

write like this:

$sql_select="select route from $client_id WHERE net_id = ".$rownum."";
$queryRes = mysql_query($sql_select);
print $sql_select;
print mysql_error();
$i=1;
while($rows=mysql_fetch_assoc($queryRes))

You need to provide #Resource returned from mysql_query() function to mysql_fetch_assoc().

Note: Mysql_* are deprecated from PHP5.3. Hence should be avoided.

mysql_fetch_assoc(): 6 is not a valid MySQL result resource

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.

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL Result in line 40

This error means your query failed. mysql_query() returns false if an error occurred, you are then passing false to mysql_fetch_array() which is triggering the error message.

Your query could be failing due to a missing/wrong table or field. To see the detailed error, print out the result of mysql_error().


The mysql_* library is deprecated. It is recommended to upgrade to MySQLi or PDO.

mysql_fetch_array(): supplied argument is not a valid MySQL result resource... [snip]

You are trying to use mysql_fetch_array on a string when it excpets a resource handle.

include dirname(__FILE__).'/db_connection.php';
$eventid = $_GET['id'];
$user = $_SESSION['account'];
$sqlevents = "SELECT * FROM events WHERE ID = $eventid";
$result = mysql_query($sqlevents);

// ....

while($event = mysql_fetch_array($result)){/* ... */ }

However, if no one has told you this by now you should not be using the ext/mysql extension. Its deprecated, use PDO or mysqli instead. mysqli has an api ver similar to ext/mysql and supports more features of MySQL.. but PDO is much easier to work with IMO.

Same thing with PDO:

$db = new PDO($dsn, $user, $pass);
$stmt = $db->prepare('SELECT * FROM events WHERE ID = ?');
$stmt->execute(array($eventid));

while (false !== ($row = $stmt->fetch(PDO::FETCH_ASSOC))) { /* ... */ }


Related Topics



Leave a reply



Submit