Hi everyone. I am unable to connect to my database I have set up. I have successfully connected to
my mysql database many times. This is why I am so shocked and stumped that I can't connect. I am
coding in php and I have checked all the common errors that I have had in the past - typos, forgot to list a variable, etc.
Now, though, I swear I have the correct name, password and anything else that I can control from what I see,
could someone suggest what I could do to start fixing this problem?
Thanks.
Here is what my webpage error reports:
I am unable to connect to the database because of: Access denied for user 'myrealusername'@'localhost' (using password: YES)
error_log:
PHP Warning: mysql_connect(): Access denied for user 'myrealusername' (using password: YES) in /home3/path/to/public_html/directory/submit.php on line 50
I put in parenthesis the 50th line in my code as it is referenced here.
Here is my code:
Code:
<?php
// databaseConnect();
if(isset($_POST['name'])){$name = $_POST['name'];}
if(isset($_POST['email'])){$email = $_POST['email'];}
if(isset($_POST['qor'])){$qor = $_POST['qor'];}
$db_hostname = "localhost"; //Host
$db_username = "username_here"; //Username
$db_pass = "password_here"; //Password
$db_name = "database_name"; //Database Name
$dbc=mysql_connect($db_hostname, $db_username, $db_pass, $db_name) or die ('I am unable to connect to the database because of: ' . mysql_error()); //(Line 50)
echo "connected to database" . "<br>";
$dbselect = mysql_select_db("tablename", $dbc) or die ('I am unable to find that table because of: ' . mysql_error());
$dbc=mysql_connect($db_hostname, $db_username, $db_pass) or die ('I am unable to connect to the database because of: ' . mysql_error()); //(Line 50)
echo "connected to database" . "<br>";
$dbselect = mysql_select_db($db_name, $dbc) or die ('I am unable to find that table because of: ' . mysql_error());
Access denied for user 'myrealusername'@'localhost' (using password: YES)
try chaning localhost to 127.0.0.1
They may appear to be the same in any other situation, but for MySQL they are very different. When you grant permissions, 127.0.0.1 is not the same host as "localhost". Give it a shot, this might be what's holding you up. It otherwise looks like OK code to me.
Your issue is a mysql permissions/access issue, not really a PHP one. If you have "root" mysql user access, you should provide us the output of:
SELECT user,host FROM mysql.user;
I use (, ; : -) as I please- instead of learning the English language specification: I decided to learn Scheme and Java;
Bookmarks