?
Solved

"Fatal error: Call to a member function MoveNext() on a non-object"

Posted on 2009-04-18
8
Medium Priority
?
2,694 Views
Last Modified: 2012-05-06
Hi, experts!

I have a short PHP code, and the code in the Code box is part of the code.

When I uploaded and  opened the page, I I got the following error
Fatal error: Call to a member function MoveNext() on a non-object in /home/public_html/test.php on line 10
while (!$result->EOF)
    {
 
      echo '<tr>' .
        
          '<td>' . $result -> fields ['Name']. '</td>' .
          '<td>' . $result -> fields ['Email'] . '</td>' .
          '</tr>';
 
        $result -> MoveNext ();
   }

Open in new window

0
Comment
Question by:duta
8 Comments
 
LVL 3

Accepted Solution

by:
Chimeraza earned 1000 total points
ID: 24175132
Your constructor to the class is probably not initializing $result correctly and so it is a null value.  Hence..it would work for the while loop (while not null) as well as the $result -> fields (output null)... but when it needs to perform a function it gives the error (hence error on line 10)..

If this doesn't help you solve it then I need to see your class to help you further.

Regards
Nick
0
 

Author Comment

by:duta
ID: 24175191
Thank  you so much for your kind, prompt reply.

The code is in the Code Snippet.

<?php
 
function printEntries($result)
{
echo
'<style type="text/css">
      table.myTable td
{
  border: solid 1px black;
}
table.myTable th
{
  border: solid 1px black;
  background-color:silver;
}
</style>';
 
 echo '<table class = "myTable"><tr><th> Name</th><th> Email</th></tr>';
 
    while (!$result->EOF)
    {
 
      echo '<tr>' .
          
          '<td>' . $result -> fields ['Name']. '</td>' .
          '<td>' . $result -> fields ['Email'] . '</td>' .
          '</tr>';
 
        $result -> MoveNext ();
   }
echo '</table>';
 
echo "<br />\n[" . $result->RecordCount() . " rows returned]\n";
 
$db->Close();
 
}
 
?>

Open in new window

0
 
LVL 11

Assisted Solution

by:Chris Gralike
Chris Gralike earned 1000 total points
ID: 24175213
You are not declaring object $result, or object $result isnt an object but a resource.

Where exactly is $db-> declared? and where is $result declared?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 11

Expert Comment

by:Chris Gralike
ID: 24175269
If you are using PEAR, or some other class i expect to see something like this.


$connection = DB::connect(mysql://$db_username:$db_password@$db_host/$db_database");
 
$query = "SELECT CURDATE() as date";
 
$connection->query($query);
 
if (DB::isError($result)){
      die("Could not query the database <br />".$query." ".DB::errorMessage($result));
}else{
while ($result_row = $result->fetchRow()) {
echo $result_row[0];
}
$connection->close();

Open in new window

0
 
LVL 3

Expert Comment

by:Chimeraza
ID: 24175299
You there should be a line that says $result = new something();

Can you find that anywhere?
0
 
LVL 6

Expert Comment

by:JoachimMartinsen
ID: 24175361
Just remove a space from line 10:
CHANGE THIS
$result -> MoveNext ();
 
TO THIS
$result -> MoveNext();

Open in new window

0
 
LVL 11

Expert Comment

by:Chris Gralike
ID: 24179880

@Chimeraza

With static classes this is not always the case.
http://nl.php.net/manual/en/language.oop5.static.php
Rgrds,
0
 
LVL 3

Expert Comment

by:Chimeraza
ID: 24182435
@Chris_Gralike

Noted.  Thanks!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question