Access denied to mysql database

tomfordx

New Member
Messages
4
Reaction score
0
Points
0
Basically I am trying to run some code to insert some data into my database. I have a seperate file to connect to the data base:

Code:
<?php
$link = mysql_connect('localhost', '*****', '*****');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('******', $link);
if (!$db_selected) {
    die ('Can\'t use database : ' . mysql_error());
?>

Then in a file called register.php I include the config.php and that page then loads perfectly fine. you hit register and tries to insert the data into the database I get this error message:

Access denied for user '*****'@'localhost' (using password: NO)

Now I have double checked my user and password information for the database and it is correct so HELP!
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
Have you remembered to prefix your database name and MySQL user name with your cPanel user name? (The format is cpanelusername_databasename and cpanelusername_databaseusername.)
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Access denied for user '*****'@'localhost' (using password: NO)
The script is trying to connect without a password somewhere. Perhaps another mysql function is being called before mysql_connect, which will attempt to connect with default parameters. This is one reason the connection should always be specified when calling the mysql functions.

The mysql extension is outdated and on its way to deprecation. Instead, use PDO, which has many useful improvements, such as prepared statements and support for the Traversable interface, so you can loop over results with foreach. If you need a PDO tutorial, try "Writing MySQL Scripts with PHP and PDO".

Be sure to read the MySQL articles on the X10 Wiki.
 
Last edited:
Top