0

Greeting's I'm currently taking my first attempt at developing a login for my website. For this login I'm utilizing PHP and MySQL. My problem is that I keep recieving the error below... I've tried exhausted all possibilities of how to rename "require_once" input to my knowledge, but still know luck.

Warning: require_once(C:\Users\Derek\Fall_2013\PS-WebDesign\includes\constants.php) [function.require-once]: failed to open stream: No such file or directory in D:\Hosting\11311638\html\classes\Mysql.php on line 3

Fatal error: require_once() [function.require]: Failed opening required 'C:\Users\Derek\Fall_2013\PS-WebDesign\includes\constants.php' (include_path='.;C:\php\pear') in D:\Hosting\11311638\html\classes\Mysql.php on line 3

Below is the line of code that is producing the Fatal error, My question is have I not called the file correctly or is there code my feeble mind is missing? The error is on the 3rd line "require_once...."

<?php

require_once 'includes/constants.php';

class Mysql {
    private $conn;
    function __construct() {
        $this->conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die(
        'You ***'d up.');   
    }

    function verify_Username_and_Pass($un, $pwd) {

        $query = "SELECT *
        FROM users
        WHERE username = ? AND password = ?
        LIMIT 1";

        if($stmt = $this->conn->prepare($query)) {
            $stmt->bind_param('ss', $un, $pwd);
            $stmt->execute();

            if($stmt->fetch()) {
                $stmt->close();
                return true;
            }
        }
    }
}
Sammitch
  • 30,782
  • 7
  • 50
  • 77
John Smith
  • 1
  • 1
  • 1
  • 7
    the error's very clear. the file you're trying to `require` is not there: `No such file or directory`. Since it can't be included, require is doing what it's supposed to and killing your script. – Marc B Oct 16 '13 at 21:58
  • the require path should be relative to the root of your apache directory – Joren Oct 16 '13 at 22:02
  • and you have a syntax error in your `die` – Ibu Oct 16 '13 at 22:02
  • Yes, I believe that is indeed what is causing the error. However I've created my constants.php file already, so why is it not recognizing it. May I ask if you don't mind, how would I go around correcting this problem. – John Smith Oct 16 '13 at 22:03
  • I cleaned up a bit, omitted unnecessary data, I hope you don't mind. Now: the file you are including is not there. Can you see `C:\Users\Derek\Fall_2013\PS-WebDesign\includes\constants.php`? In that case it may be a rights permission. If it's the wrong dir, remember that the _first_ file in a request basically determines the working dir (examine it with `getcwd()`, possibly alter it with `chdir()` if needed, but only as a last resort) including relative to the `__FILE__` or `__DIR__` constants would be prefered. – Wrikken Oct 16 '13 at 22:03
  • 1
    If the path is relative to the current directory, you can use `require_once __DIR__.'/includes/constants.php';` – Matt Browne Oct 16 '13 at 22:04
  • To remove confusions, use static relative linking to the php file from the file you mentioned above – Uday Hiwarale Oct 16 '13 at 22:06
  • And @sammitch for _some_ reason puts back in all the mysql code which isn't to the point. Ah well.. so much for my editing efforts. – Wrikken Oct 16 '13 at 22:06
  • Thank you everyone for your responses! I'll let you know when I get this working. Any additional advice is appreciated. – John Smith Oct 16 '13 at 22:07
  • Fixed it! I cut the includes/constant.php and pasted it into classes/constant.php and now it works... Not sure why that worked but it does. – John Smith Oct 16 '13 at 22:38
  • One often runs into this error, and to quickly troubleshoot it, follow these steps : https://stackoverflow.com/a/36577021/2873507 – Vic Seedoubleyew Apr 12 '16 at 15:36

2 Answers2

0

The path either needs to be an absolute path to the file you want to include or you need to add its location to your include path.

http://php.net/manual/en/function.set-include-path.php

Gavin
  • 2,123
  • 1
  • 15
  • 19
0

is this include file in the root directory?

You should also remove the blank line above the include line. Lsatly, the syntax for die should read die(mysqli_error() 'You ***'d up.');

cmd
  • 11,622
  • 7
  • 51
  • 61
lfort
  • 1