Jump to content

Php And Mysql

Recommended Posts

Hi! Im new to the php and mysql world and am trying to figure out the mysql_connect. In cPanel --> Manage mySQL, I have my database setup,


named = username_dbname

my user has all privileges for that database.


I dont know what im missing. Here is my code. and the error that I get.




$oconn=mysql_connect ("localhost", "username_", "******") or die ("I cannot connect to the database because: " . mysql_error());

mysql_select_db ("username_dbname");




mysql_connect(): Access denied for user: 'username_@localhost' (Using password: YES) in /home/username/public_html/admin/loginpost.php on line 5


For the error and code and changed my username to "username" and put *s instead of my password. I only have two php pages on my whole site, login.php which has a form to pass a username and password to connect to the site, (tblUsers in my db.) and this page. Am I missing another page? Am I missing other settings?


Your help is much appreciated,



Link to comment
Share on other sites

:) Welcome to the forums Jacques :)



The normal steps to use a database is

in MySql

create a database with a name like nuke

create a user for the database like cmsuser

with a password of xyz123


then add cmsuser to the nuke database


The connect string should be in the form of


$dbh=mysql_connect ("localhost", "cpanelname_cmsuser", "xyz123") or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db ("cpanelname_nuke");



The most common error is forgetting to add the user to the database in MySql

and will result in an error much like yours.

Link to comment
Share on other sites

Don and GroovyFish, thanks for that help. I was just using cpanelname_ as my username, so I added a new user and added it to the db and it worked great!


Thanks for all your help.


Glad to be on-board!



Link to comment
Share on other sites

  • 1 month later...

Rather than starting a new post, I found this one and thought I'd ask it here.


I haven't used MySQL Administrator in a while so I have forgotten the password. Since I am starting over with a database, I made a new one and added a user (for which I know the password) and gave it all privileges.


However, when starting the MySQL Administrator, I type in the username cpanelname_username and the password (both I know are correct) but I get this error:


MySQL Error Number: 1045

Access Denied to User:

'cpanelname_username@<stuff> us.da.qwest.net' (Using Password: YES)


Now, the Server Host is correct and the port is 3306 (don't know if that makes a difference...).


I had this working months ago and encountered a problem like this but cannot remember how I fixed it.


BTW, I also created a new user and tried it there, but got the same error.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...