I started using the Tutis login script. I made some changes but the following is giving me errors:
I want to list all the registered users but the Foreach Loop isn’t working.
I created a new function in the member.class.php:
// Registered Users
public function rusers()
{
global $database;
$notice = new notice;
$users = $database->query('SELECT id, username, date FROM users');
$return_form = 1;
$user = "<table>"
. "<tr>"
. "<td>ID</td>"
. "<td>UserName</td>"
. "<td>Date</td>"
. "</tr>";
// Function in the database.class.php
$result = $database->foreachloop($users);
foreach ($result as $row)
{
$user.= "<tr><td>".$row['id']."</td>";
$user.= "<td>".$row['username']."</td><td>".$row['date']."</td></tr>";
}
$user.= "</table>";
/* Combine Data */
$data = "";
/* Do we need the login form? */
if ($return_form == 1)
{
$data .= $user;
}
/* Return data */
return $notice->report() . $data;
}
And added the foreachloop() function in the database.class.php
public function foreachloop($result)
{
return $this->statement->fetch(PDO::FETCH_ASSOC);
}
But I get the following long error:
*Warning: Illegal string offset 'id' in C:\wamp\www\loginoop3\assets\member.class.php on line 996
Warning: Illegal string offset 'username' in C:\wamp\www\loginoop3\assets\member.class.php on line 997
Warning: Illegal string offset 'date' in C:\wamp\www\loginoop3\assets\member.class.php on line 997
Warning: Illegal string offset 'id' in C:\wamp\www\loginoop3\assets\member.class.php on line 996
Warning: Illegal string offset 'username' in C:\wamp\www\loginoop3\assets\member.class.php on line 997
Warning: Illegal string offset 'date' in C:\wamp\www\loginoop3\assets\member.class.php on line 997*
And the output is:
*ID UserName Date
t t t
2 2 2*
Here the 2 number means the user ID and the “t” letter is the “test” username but only show the first letter… And only shows one user but there are more users.
I don’t know whats wrong. Are there someone any suggestion?
This login uses OOP PDO. And I tried to do this changes by the rowCount() as it had a new function in the database.class.php with the following content:
public function affected($result)
{
return $this->statement->rowCount();
}
to user961627 (original function from the creator of tutis login):
Function in member.class.php:
Call it by using: