Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

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

Fatal Error on Line 38 -- at $result



10:26 pm on Apr 30, 2012 (gmt 0)

Here's my code:


// create short variable names

if (!$state)
echo 'You have not entered all the required details.<br />'
.'Please go back and try again.';
if (!get_magic_quotes_gpc())
$state = addslashes($state);

$con = mysql_connect("localhost","qfs","abc123","applicants");
if (!$con)
die('Could not connect: ' . mysql_error());

$query = "insert into applicants values

$result = $db->query($query);
if ($result)
echo $db->affected_rows.' application inserted into database.';



10:30 pm on Apr 30, 2012 (gmt 0)

Oh, I think I corrected it now:

$result = $con->query($query);


10:43 pm on Apr 30, 2012 (gmt 0)

No, same problem. Any ideas?


11:29 pm on Apr 30, 2012 (gmt 0)

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Why are you trying to use some query function as if it were from some object?

You want mysql_query() which will accept $con as a variable.

I'm thinking you used some database class library that contained query() in the past and you forgot to include that class library as part of your current code.


4:13 pm on May 1, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Wouldn't that give an "undefined function:query" error though?

$result = $db->query($query);

What is $db? It should be your database object. You make the connection, but fail to link to it. How does $db become assigned as the database object?

Featured Threads

Hot Threads This Week

Hot Threads This Month