Access Denied for user

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
murias
Forum Newbie
Posts: 2
Joined: Sun Nov 29, 2009 12:39 pm

Access Denied for user

Post by murias »

Hello to all, thanx for taKing the time to read this and to assist. I feel like this is going to be more than likely a very simple thing, but has eluded me thus far.

This code worked on my local development machine, but then I transferred it over to a FreeBSD machine, which I have just built and it does not function the same way.
The exact errors I get are:
Warning: mysql_query() [function.mysql-query]: Access denied for user 'murias'@'localhost' (using password: NO) in /usr/home/www/develop.develop/property/add_user.php on line 47

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /usr/home/www/develop.develop/property/add_user.php on line 47
Code from the script lines 2 and 42 through 47:

Code: Select all

include_once ('mysql.inc.php') ;
$query = "INSERT INTO users VALUES('', '".$_POST["user"]."', "
 ."PASSWORD('".$_POST["password"]."'),"
 ."'".$_POST["email"]."',"
 ."'".$_POST["management"]."', "
 ."'".$_POST["permission"]."', '', '', '')" ;
 $result = mysql_query($query);
Code from mysql.inc.php:

Code: Select all

$db_hostname = "localhost:3306";
$db_database = "property_management";
$db_username = "property";
$db_password = "changedtoprotecttheinnocent";
 
        $connection = mysql_connect($db_hostname, $db_username, $db_password) or die(mysql_error());
        mysql_select_db($db_database, $connection);
function open_db_connection()
    {
        $connection = mysql_connect($db_hostname, $db_username, $db_password) or die(mysql_error());
        mysql_select_db($db_database, $connection);
    }
    
function close_db_connection()
    {
        if ($connection) { mysql_close($connection) ; }
    }   
 
The path to the include file is correct.
Permissions on the include are identical to those of the referrer. But have changed to 777 to test, and also attempted changing owner.
This code as it stands worked on a my desktop under MAMP.
Password and user in the include are correct: when I copy and paste it into the the actual script all of this works.
What I find odd, is that the db user is actually property, it is like the server is denying the existence of the include, it is trying to use a different user, and not what is declared in the include.
Again, if I put the very same connection data out of the include and put it exactly as is into the main script, it all works.

It would be awesome if someone could direct me to what I am "blatantly" overlooking.
Thank you greatly in advance.
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: Access Denied for user

Post by iankent »

The odd thing is, you're passing in a password but getting this error
Access denied for user 'murias'@'localhost' (using password: NO)
so it appears mysql doesn't think you're providing a password. Even if the password is wrong, that should still be YES afaik.

can you login to mysql via the command line from that machine using 'mysql -u usernamehere -p' or via phpmyadmin/mysql query browser?

edit: ignore all that :)
when you create the connection it only has scope within the function you created it in. in open_db_connection you need to call

Code: Select all

 
global $connection, $db_hostname, $db_username, $db_password, $db_database;
 
before you open the connection, that way php knows you mean the global versions of them :)
murias
Forum Newbie
Posts: 2
Joined: Sun Nov 29, 2009 12:39 pm

Re: Access Denied for user

Post by murias »

iankent wrote: edit: ignore all that :)
when you create the connection it only has scope within the function you created it in. in open_db_connection you need to call

Code: Select all

 
global $connection, $db_hostname, $db_username, $db_password, $db_database;
 
before you open the connection, that way php knows you mean the global versions of them :)
Not so sure I follow here.
Post Reply