-2

Warning: include_once(../lib/Database.php): failed to open stream: No such file or directory in C:\xampp\htdocs\project\e-commerce\classes\Adminlogin.php on line 4

Warning: include_once(): Failed opening '../lib/Database.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\project\e-commerce\classes\Adminlogin.php on line 4

Fatal error: Class 'Database' not found in C:\xampp\htdocs\project\e-commerce\classes\Adminlogin.php on line 17

How can i solve this problem? My code is here...

<?php
    include '../lib/Session.php';
    Session::checkLogin();
    include_once '../lib/Database.php';
    include_once '../helpers/Format.php';
?>
<?php
    /**
    * Adminlogin Class
    */
    class Adminlogin {
        private $db; 
        private $fm; 

        public function __construct(){
            $this->db = new Database();
            $this->fm = new Format();
        }

        public function adminLogin($adminUser,$adminPass){
            $adminUser = $this->fm->validation($adminUser);
            $adminPass = $this->fm->validation($adminPass);

            $adminUser = mysqli_real_escape_string($this->db->link, $adminUser);
            $adminPass = mysqli_real_escape_string($this->db->link, $adminPass);

            if (empty($adminUser) || empty($adminPass)) {
                $loginmsg = "Username and Password must not be empty..!!";
                return $loginmsg;
            } else {
                $query = "SELECT * FROM tbl_admin WHERE adminUser = '$adminUser' AND adminPass = '$adminPass'";
                $result = $this->db->select($query); 
                if ($result != false) {
                    $value = $result->fetch_assoc();

                    Session::set("adminlogin", true);
                    Session::set("adminId", $value['adminId']);
                    Session::set("adminName", $value['adminName']);
                    Session::set("adminUser", $value['adminUser']);
                    header("Location:dashbord.php");
                } else{
                    $loginmsg = "Username and Password not match !!";
                    return $loginmsg;
                }
            }
        }
    }
?>
Tieson T.
  • 20,774
  • 6
  • 77
  • 92
Afnan
  • 1
  • 1
  • 3
  • 1
    So, what are your thoughts on "file not found"? How would anyone else know the relation of your directory structures, unless explained in the question? (Btw, relative paths are usually relative to the *invocation* script, not includes among each other.) – mario Sep 20 '17 at 19:02

3 Answers3

0

What is the structure of your folders and files? this

include_once '../lib/Database.php';

mean that, your folder and files must be e-commerce\classes\Adminlogin.php e-commerce\libs\Database.php

Walter
  • 81
  • 1
  • 9
0

The problem is that php tries to find your classes in your include_path and it is set to C:\xampp\php\PEAR

You can try to use this approach:

include_once $_SERVER['DOCUMENT_ROOT'] . "/lib/Session.php";
include_once $_SERVER['DOCUMENT_ROOT'] . "/lib/Database.php";
include_once $_SERVER['DOCUMENT_ROOT'] . "/helpers/Format.php";

But I find it better to define global constant and use it later in the code:

define('HOME_DIR', 'C:\xampp\htdocs\project\e-commerce\');

include_once HOME_DIR . "/lib/Session.php";
include_once HOME_DIR . "/lib/Database.php";
include_once HOME_DIR . "/helpers/Format.php";

And when you migrate to production you will have to re-define HOME_DIR to whatever it will be on your server.

Pepe Bolo
  • 71
  • 4
  • its not working... now this problem is Warning: include_once(C:/xampp/htdocs/lib/Session.php): failed to open stream: No such file or directory in C:\xampp\htdocs\project\e-commerce\classes\Adminlogin.php on line 2 Warning: include_once(): Failed opening 'C:/xampp/htdocs/lib/Session.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\project\e-commerce\classes\Adminlogin.php on line 2 Fatal error: Class 'Session' not found in C:\xampp\htdocs\project\e-commerce\classes\Adminlogin.php on line 3 – Afnan Sep 21 '17 at 12:26
  • @Afnan Please try the second code block with define(). If this is not suitable for you, change your DOCUMENT_ROOT for this project, so that it points to your root project directory (C:\xampp\htdocs\project\e-commerce\). You can reference this question: https://stackoverflow.com/questions/10157333/xampp-change-document-root?answertab=votes#tab-top – Pepe Bolo Sep 21 '17 at 13:13
0

Try this approach:

<?php 
    define('__ROOT__', dirname(dirname(__FILE__))); 
    require_once(__ROOT__.'../../lib/session.php');
?>
Pang
  • 9,564
  • 146
  • 81
  • 122