0

I'va a constant named __Username in this, there are a username for db access. But, sounds the error message, it cant resolve this constant. What I've does wrong?

config.php

<?php

define("__Password", "xxx");
define("__Database", "xxx");
define("__Table", "xxx");
define("__Username", "xxx");

?>

db.php

<?php

include('config.php');

function validateUser($username, $password){
    $pswd = '';

    $db_handle = mysql_connect('127.0.0.1', __Username, __Password);
    $db_found = mysql_select_db(__Database, $db_handle);

    if($db_found) {
        $query = "select * from users where username = '" . $username . "'";

        $result = mysql_query($query) or die(mysql_error());

        while($db_field = mysql_fetch_assoc($result))
        {
            $pswd = $db_field['password'];
        }
    }
    else
    {
        return false;
    }

    if($pswd == $password)
    {
        return true;
    }

    return false;
}
?>

Has someone an idea?

Marcel Hoffmann
  • 973
  • 1
  • 8
  • 15
  • Can your constants start with a double underscore? What happens if you use a single or no underscore? – Damon Jan 24 '15 at 20:20
  • 2
    when you try to just echo __Username, what do you get? BTW... you should use MySQLi or PDO_MySQL instead of mysql_ functions. – Lupin Jan 24 '15 at 20:20
  • 2
    Please post the actual error message. – elixenide Jan 24 '15 at 20:20
  • 1
    Also, as @Lupin says: Please [don't use `mysql_*`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php?rq=1); the `mysql_*` functions are outdated, [deprecated](http://us3.php.net/manual/en/intro.mysql.php), and insecure. Use [`MySQLi`](http://us3.php.net/manual/en/book.mysqli.php) or [`PDO`](http://us3.php.net/manual/en/intro.pdo.php) instead. – elixenide Jan 24 '15 at 20:21
  • Though you can use double underscore for constants, why would someone do that? As the other commenters have stated, please don't use mysql_ as it is to store passwords in plain text – baao Jan 24 '15 at 20:31
  • If I use echo, I'll get the name of the constant, that mean's the constants wount be found, right? But why? – Marcel Hoffmann Jan 24 '15 at 21:45

0 Answers0