php include error not findind the path

2019-01-02 21:43发布

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:

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

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:\wamp\www\proiect1-test\scripts\login.php on line 3 Warning: include(): Failed opening '../inc/db.php' for inclusion (include_path='.;C:\php\pear') in E:\wamp\www\proiect1-test\scripts\login.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.

标签: php mysql
1条回答
凸逼喃波丸
2楼-- · 2019-01-02 22:18

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:

include("/path/from/root/to/inc/db.php"); 

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"); 
查看更多
登录 后发表回答