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.
|
|
|
|
|
![]() |
||
Fatal error: call to a member function funtion() on a non-object
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
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 |
|
|
|
#2
|
|||
|
|||
|
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
|
|
#3
|
|||
|
|||
|
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 : ) |
![]() |
| Tags |
| fatal error |
| Thread Tools | |
|
|
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 |