0

I have main folder that include config.php file.

config.php

<?php
    $db = new mysqli('localhost', 'root', null, 'diamonds2');
    if ($db->connect_error)
        die($db->connect_error);
    $db->query("SET NAMES 'utf8'") or die($db->error);

(all php files are without closing tag)

another file in this folder checklogin.php:

<?php
session_start();
include('config.php');
$connect = false;
$admin = false;
if (isset($_SESSION['connect']) && $_SESSION['connect']) {
    if ($_SESSION['admin'])
        $admin = true;
}
elseif (isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
    $stmt = $db->prepare("SELECT `id`, `name`, `permission` FROM `users`    WHERE `username` = ? AND `password` = ?") or die($db->error);
    $stmt->bind_param('ss', $_COOKIE['username'], $_COOKIE['password']);
    $stmt->execute();
    $stmt->store_result();
    if ($stmt->num_rows) {
        $stmt->bind_result($id, $name, $per);
        $_SESSION['connect'] = true;
        $stmt->fetch();
        if ($per) { 
            $_SESSION['admin'] = true;
            $admin = true;
        }
        $_SESSION['id'] = $id;
        $_SESSION['username'] = $name;
    }
    else {
        $_SESSION['connect'] = false;
        $_SESSION['admin'] = false;
    }
}

Now I have admin folder that have the files:

checkadminlogin.php:

<?php   
include('../checklogin.php');
if (!$admin) {
    header('Location: ../login.php');
    die;
}

& users.php file:

<?php
    include('checkadminlogin.php');
?>
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <body>
        <h1 class="title">Users Page</h1>
        <br />
        <?php
           $result = $db->query("SELECT * FROM `users`") or die($db->error);

Now when I run the users.php file, I get this errors:

Notice: Undefined variable: db in C:\xampp\htdocs\newsite\newsite\admin\users.php on line 13

Fatal error: Call to a member function query() on null in C:\xampp\htdocs\newsite\newsite\admin\users.php on line 13

I did it few times in other projects and its works fine.
I dont know why its not working right now.

My folders tree

folders tree http://www.interload.co.il/upload/4827714.png

When I try to echo from the config file nothing apears. So I think the problem come from the include, meaning its not include the config.php file.

In php.ini I turn on display errors & I set error_reporting to E_ALL but there is no another errors.

Community
  • 1
  • 1
Kaki Baleven
  • 355
  • 3
  • 7
  • 19

0 Answers0