By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

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

P: 2
Call to a member function free() on a non-object error can anyone help plz?
Aug 2 '07 #1
Share this Question
Share on Google+
5 Replies


P: 2
sorry here,s the code so far :
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  <title>Book-O-Rama Search results</title>
  4. </head>
  5. <body>
  6. <h1>Book-O-Rama Search Results</h1>
  7.  
  8. <?php
  9.   // create short variable names
  10.   $searchtype=$_POST['searchtype'];
  11.   $searchterm=$_POST['searchterm'];
  12.   $searchterm= trim($searchterm);
  13. if (!$searchtype || !$searchterm)
  14. {
  15.    echo 'You have not entered search details. Please go back and try again.';
  16.    exit;
  17. }
  18. if (!get_magic_quotes_gpc())
  19. {
  20.   $searchtype = addslashes($searchtype);
  21.   $searchterm = addslashes($searchterm);
  22. }
  23.  
  24. @ $db = new mysqli('localhost' , 'bookorama' , 'bookorama123' , 'books' );
  25.  
  26. if (mysqli_connect_errno())
  27. {
  28.    echo 'Error: Could not connect to database. Please try again later.' ;
  29.    exit;
  30. }
  31. $query ="select * from books where ".$searchtype."like '%" .$searchterm. "%'" ;
  32. $result = $db->query($query);
  33. $num_results = $result->num_rows;
  34. echo '<p>Number of books found: '.$num_results. '</p>' ;
  35. for ($i=0; $i <$num_results; $i++)
  36. {
  37.    $row = $result->fetch_assoc();
  38.    echo '<p><strong>' .($i+1).' . Title: ';
  39.    echo htmlspecialchars(stripslashes($row['title']));
  40.    echo '</strong><br />Author: ';
  41.    echo stripslashes($row['author']);
  42.    echo '<br />ISBN: ';
  43.    echo stripslashes($row['isbn']);
  44.    echo '<br />Price: ';
  45.    echo stripslashes($row['price']);
  46.    echo '</p>';
  47. }
  48.    $result->free();       <--- error comes up here
  49.    $db->close(); 
  50.  
  51. ?>
  52. </body>
  53. </html>
Aug 2 '07 #2

kovik
Expert 100+
P: 1,044
It means that you are trying to call a function from an variable that isn't an object -- EXACTLY what it states.

i.e.

[php]$pObj = NULL;
$pObj->free();[/php]

That will produce the same error because $pObj is not actually an object, even though it's variable name would make you think so.
Aug 2 '07 #3

kovik
Expert 100+
P: 1,044
There is no "free()" function. MySQL resources don't have any functions of their own at all.

Maybe you're after mysql_free_result().
Aug 2 '07 #4

pbmods
Expert 5K+
P: 5,821
Changed thread title to better describe the problem (did you know that threads whose titles contain phrases such as, 'please help' actually get FEWER responses?).
Aug 2 '07 #5

pbmods
Expert 5K+
P: 5,821
Merged duplicate threads.
Aug 2 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.