0

I have a database connection file in my web application and for some reason the server is trying to connect to the location of: ***.**.**.215 for the ip address rather than: ***.**.**.222 which is what is typed in the file. The code is below:

<?php // Configure the following items to match your database! // Database Location $location = '***.**.**.222'; // Database Name $name = ''; // Database Username $username = ''; // Database Password $Password = ''; // Do not alter anything beyond this line! // Create connection $con=mysqli_connect($location,$username,$password,$name); // Check connection if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } ?> 

Google Chrome shows this exact error message: I removed the credentials from it.

Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'username'@'***.**.**.215' (using password: NO) in /home/www/hiddenforsecurity/shop/config/connect.php on line 20 Failed to connect to MySQL: Access denied for user 'username'@'***.**.**.215' (using password: NO) 

I'm not sure what in the world to do or what is wrong, when I replace $location in the $con with the actual ip address, it works perfect. It's just when I use the variable $location that it doesn't work.

I removed important private credentials from this question. Sorry hackers.

14
  • Sounds like you're editing the wrong file? Try erasing everything in this file and run it again. Just do it, to be sure. Commented Oct 9, 2013 at 16:16
  • No i'm editing the right file. It is a application I've built from the ground up with no frameworks. I know it is the right one. Commented Oct 9, 2013 at 16:17
  • 1
    using password: NO – that makes me strongly suspect that this is not really your code, or it is not the point in the script where that error message originates from. Commented Oct 9, 2013 at 16:17
  • Just try it, for science. Commented Oct 9, 2013 at 16:17
  • You may have to switch from $location = '***.**.**.222'; to $location = 'localhost'; - give that a try. Commented Oct 9, 2013 at 16:19

2 Answers 2

3
// Database Password $Password = ''; // Create connection $con=mysqli_connect($location,$username,$password,$name); 

Change the capital $Password to $password.

Sign up to request clarification or add additional context in comments.

Comments

0

You're on an client with ip address *.215 and you're trying to connect to MySQL server with ip address *.222, so make sure that the user '$username' on the MySQL server is allowed to connect from the ip *.215 you're using. (by default every user is allowed to connect only from local 127.0.0.1).

The connection you're trying to establish doesn't use password, notice that the variable you're using in the mysqli_connect(...) function is written $password and in the configuration above $Password (first letter upper case).

I suggest you to check the error log file (if you're using apache it is error.log inside the httpd folder), because in that file are logged all warning and errors and can help you solve problems, in this case probably there is something like this:

Variable $password undefined in page.php on line nnn.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.