Asked  7 Months ago    Answers:  5   Viewed   18 times

I have this little code, which in fact is a login script which check if the register is on, and show it after the login button:

if(isset($_POST['user']) && isset($_POST['pass']))
    $password = $_POST['pass'];
    $username = $_POST['user'];

    $sql = "SELECT * FROM `users` WHERE `user` = '".$username."' AND `password` = '".$password."'";
    $rez = $pdo->query($sql);   
    if($rez->fetchColumn()  > 0)

    else {echo '<p align="center">...</p>';}
    else { echo '<p align="center">...</p>'; }
    <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <form name="form1" method="post" action="login">
    <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
    <td colspan="3"><strong>Member Login </strong></td>
    <td width="78">Username</td>
    <td width="6">:</td>
    <td width="294"><input name="user" type="text" id="user"></td>
    <td><input name="pass" type="password" id="pass"></td>
    <td><input type="submit" name="Submit" value="Login"></td>
    <?php $sql = "SELECT setare FROM setari WHERE nume_setare = 'OPEN_REG'";
    $openreg = $pdo->query($sql)->fetch();
    if($openreg['setare'] == 1)
    <td><a href="register">Inregistrare</a></td>
    </tr><?php } ?>

My problem is this line:

include("../inc/db.php"); Warning: include(E:/wamp/www//inc/db.php): failed to open stream: No such file or directory in E:wampwwwproiect1-testscriptslogin.php on line 3 Warning: include(): Failed opening '../inc/db.php' for inclusion (include_path='.;C:phppear') in E:wampwwwproiect1-testscriptslogin.php on line 3

and i can't figure it out where i'm wrong. The path is correct, and if i hit the login button, it works.If i hit login button with an inccorect combination of username and password, the warning disappear. However, it doesn't include that when i open it for the first time. This login file is included in the index of the site.



Your path to that file is obviously incorrect. This commonly happens when you use a relative path to a file and then start placing files in different directories. You should use the full system path to the file to avoid this issue:


A common thing to do is define a variable or constant that defines the root path to your web files. That way if it ever changes (i.e. you change hosts) you only need to change it in one place.

In your config file:

define('ROOT_PATH', '/path/from/root/to/');

In your PHP files;

include(ROOT_PATH . "inc/db.php"); 
Wednesday, March 31, 2021
answered 7 Months ago

You need to add the after the directory name:

include(__DIR__ . "\..\another_folder\file_2.php");

This will make the path be


instead of


Also, for portability, it is advisable to use / instead of , which works on all platforms, including Windows:

include(__DIR__ . "/../another_folder/file_2.php");
Saturday, May 29, 2021
answered 5 Months ago

you can't print the result from mysqli_query, it is mysqli_resource and for dumping the error you need to change mysql_error() to mysqli_error()

$username = "bob";
$db = mysqli_connect("localhost", "username", "password", "user_data");
$sql1 = "select id from user_information where username='$username'";
$result = mysqli_query($db, $sql1) or die(mysqli_error());
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { 
    echo $row['id'].'<br>'; 
Saturday, May 29, 2021
answered 5 Months ago

yo need create the user "pma" in mysql or change this lines(user and password for mysql):

/* User for advanced features */
$cfg['Servers'][$i]['controluser'] = 'pma'; 
$cfg['Servers'][$i]['controlpass'] = '';

Linux: /etc/phpmyadmin/

Tuesday, July 13, 2021
answered 4 Months ago

The include() function does not access the file via HTTP, it accesses the file through the OS's own file system. So GET variables are not counted. (as they are not part of the file name).

In layman's terms, the point of include is to "copy/paste" all the contents on one file to another on the file, so that you don't have one gigantic file, but a few smaller, more maintainable ones.

Tuesday, August 17, 2021
Sergio Carneiro
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :