Fatal error: call to a member function funtion() on a non-object

This is a discussion on "Fatal error: call to a member function funtion() on a non-object" within the Databases section. This forum, and the thread "Fatal error: call to a member function funtion() on a non-object are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Databases

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Feb 26th, 2007, 21:24
New Member
Join Date: Feb 2007
Location: Ireland
Age: 26
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Fatal error: call to a member function funtion() on a non-object

Hi, I hope there is someone out there who can help me with this. I've got an interview in a few days, and PHP and MySQL might come up, so I'm giving myself a crash course. I've installed Apache 2.2, PHP 5.2 and MySQL. I'm trying to query the database, but I'm getting a message which seems to have a thousand solutions on the internet. It seems nobody really knows how to fix it, and they just try till something works. But that's not good enough : ) Here it is:

-----------------------------------------------------------------
I've created a database with some info about books and I want to search through it.

<html>
<head> <title> "Book-O-Rama!"</title></head>
<body>
<H1>Search Results</H1>

<?php

$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];
$searchterm=trim($searchterm);

if(!get_magic_quotes_gpc())
{
$searchtype=addslashes($searchtype);
$searchterm=addslashes($searchterm);
}

$db = new mysqli('localhost','bookorama','bookorama123','boo ks');

$query = "select*from books where".$searchtype." like '%".$searchterm."%'";

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

$row=$result->fetch_assoc();

echo 'Title:';
echo $row['title'];

echo '<br>Author:';
echo $row['author'];

echo '<br>ISBN:';
echo $row['isbn'];
?>

</body>
</html>
----------------------------------------------------------------
The error I'm getting is: Fatal error: Call to a member function fetch_assoc() on a non-object in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\bookQuery.php on line 28

It seems that I have misplaced certain libraries, or haven't properly defined some paths (where should I put my php.ini file? Are there any other important files that I need to put in certain places? There's lots of contradictory info on the net. What about configuring these files?)... But some people seem to have solved this problem by fixing the syntax in their code (but I can't find any errors in my code). Any help is much appreciated!

Maybe I'll be able to help you out someday : )

Tim
Reply With Quote

  #2 (permalink)  
Old Mar 4th, 2007, 20:49
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Fatal error: call to a member function funtion() on a non-object

If there is still time, have you tried looking here - http://uk.php.net/manual/en/function.mysqli-connect.php
Reply With Quote
  #3 (permalink)  
Old Mar 4th, 2007, 21:55
New Member
Join Date: Feb 2007
Location: Ireland
Age: 26
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Fatal error: call to a member function funtion() on a non-object

Hi Geoff,

Thanks for your help, but I found the mistake the next day : ) Here it is:

$query = "select*from books where".$searchtype." like '%".$searchterm."%'";

Can you spot it? There should be a space after 'where' otherwise the select statement doesn't make sense. It caused a 'false' value to be passed to $query which was then passed to $result. Then the fetch_assoc() function was called on the $result variable of type boolean, but of course it can only be called on variables of type object.
What a pain in the ass! But thanks again : )
Reply With Quote
Reply

Tags
fatal error

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Call to a non object fatal error alexgeek PHP Forum 2 Feb 21st, 2008 15:34
fatal error alexgeek Webforumz Cafe 3 Aug 27th, 2007 22:16
AJAX call function melvinoyh JavaScript Forum 2 May 31st, 2006 01:02
Fatal error: Call to a member function getName() on a non-object jono PHP Forum 1 Apr 13th, 2006 18:53
Having trouble with scripts. Fatal error: Call to undefined function: imagegif() cargi PHP Forum 5 Jan 6th, 2006 18:59


All times are GMT. The time now is 12:57.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43