homepage Welcome to WebmasterWorld Guest from 54.161.236.229
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
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
jdial




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

Here's my code:

<?php

// create short variable names
$state=$_POST['state'];



if (!$state)
{
echo 'You have not entered all the required details.<br />'
.'Please go back and try again.';
exit;
}
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
('".$state."')";

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

mysql_close($con);
?>

 

jdial




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

Oh, I think I corrected it now:

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

jdial




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

No, same problem. Any ideas?

incrediBILL




msg:4447722
 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.
[php.net...]

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.

rocknbil




msg:4448041
 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