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

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

dutaAsked:
Who is Participating?
 
ChimerazaConnect With a Mentor Commented:
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
 
dutaAuthor Commented:
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
 
Chris GralikeConnect With a Mentor SpecialistCommented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
Chris GralikeSpecialistCommented:
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
 
ChimerazaCommented:
You there should be a line that says $result = new something();

Can you find that anywhere?
0
 
JoachimMartinsenCommented:
Just remove a space from line 10:
CHANGE THIS
$result -> MoveNext ();
 
TO THIS
$result -> MoveNext();

Open in new window

0
 
Chris GralikeSpecialistCommented:

@Chimeraza

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

Noted.  Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.