Call to a member function fetch_assoc() on a non-object

1 replies
Hi,

I'm new here and equally new to PHP and MySQL. I'm getting the following error in a forum script when a member tried to send a message:

You have an error in your query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't get things to work and have rescheduled today. She doesn't know this but this' at line 1
Query: select count(id) as num from mb_messages where (message='Member message here') and (mid='22')

Fatal error: Call to a member function fetch_assoc() on a non-object in /home/fastingo/public_html/fastingologyfitnessthroughfasting/incs/sys/db.extend.class.php on line 6

The relevant code of the db.extend.class.php file (Top 15 lines) is shown below:

Code:
<?php



function DB_count_messages(&$DBobj, $extra='') {

  $query="select count(id) as num from mb_messages $extra";

  $DBobj->res=$DBobj->query($query);

  $row=$DBobj->res->fetch_assoc();

  return $row["num"];

}
Thanks in advance
Bhupinder
#code error #database error #mysql error #php error #programming error
  • Profile picture of the author espradley
    Looks like you have a quote messing with the query. The issue is that the database isn't returning any data due to the mySQL error...then php is trying to run mysql_fetch_assoc() on nothing.... thus displaying an error.

    Try this:

    function DB_count_messages(&$DBobj, $extra='') {

    $query="select count(id) as num from mb_messages $extra";

    $query = mysql_real_escape_string($query);

    $DBobj->res=$DBobj->query($query);

    $row=$DBobj->res->fetch_assoc();

    return $row["num"];

    }
    Signature

    Eddie Spradley

    {{ DiscussionBoard.errors[2987131].message }}

Trending Topics