homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

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)

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)

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?

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved