Link to home
Start Free TrialLog in
Avatar of duta
duta

asked on

"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

ASKER CERTIFIED SOLUTION
Avatar of Chimeraza
Chimeraza
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of duta
duta

ASKER

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

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

You there should be a line that says $result = new something();

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

Open in new window


@Chimeraza

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

Noted.  Thanks!