如何修复致命错误-类';用户';在php中找不到


how to fix fatal error - Class 'User' not found in php

这是用户类。

<?php
class User {
    /* 
     *public static function get_all_users()
     */
    public function get_all_users() {
        global $link;
        $result_set = $link->query("SELECT * FROM `user`");
        return $result_set;
    }
}

上面的类是我创建的对象但无法访问的用户类。显示html:的所有使用页面

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Cp1252">
<title>Admin Panel ::: </title>
</head>
<body>
    <h3>Users :</h3>
    <table border="1">
        <tr>
            <th>S.N</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Username</th>
            <th>Password</th>
            <th>E-mail</th>
            <th>Contact</th>
            <th colspan="2">Option</th>
        </tr>
        <?php 
            $user = new User();
            $result_set = $user->get_all_users();
            /* 
             *$result_set = User :: get_all_users(); - accessing user class using static keyword.
             */
            $i = 1;
            while ($row = mysqli_fetch_assoc($result_set)) {
        ?>
        <tr>
            <td><?php echo $row['id']; ?></td>
            <td><?php echo $row['first_name']; ?></td>
            <td><?php echo $row['last_name']; ?></td>
            <td><?php echo $row['username']; ?></td>
            <td><?php echo $row['password']; ?></td>
            <td><?php echo $row['email']; ?></td>
            <td><?php echo $row['Contact']; ?></td>
            <td><a href="">Update</a></td>
            <td><a href="">Delete</a></td>
        </tr>                                           
        <?php 
                $i++;
            }
        ?>
    </table>
</body>
</html>

当我创建用户类的对象时,我无法访问用户类,并且用户类在includes文件夹中,而下面的HTML文件在admin文件夹或admin ->viewuser.phpadmin->includes->user.php中,它给出了错误。

您需要在viewuser.php脚本中包含该User类!

include_once("includes/user.php");

我不确定这样组织你的文件夹是最好的方法,但它应该起作用。