VMinder Posted February 24, 2007 Share Posted February 24, 2007 I'm working on learning how to use php and mysql together, right now I am going over the tutorial for a database provided by W3Schools. Anyhow, I've done their correct coding which is: <html> <body> <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } if (mysql_query("CREATE DATABASE mydb",$con)) { echo "Database created"; } else { echo "Error creating database: " . mysql_error(); } ?> </body> </html> Yes I did put in my username and password, I used the actual login information inorder to access my CPanel since I was not sure. It gives me this error: Error creating database: Access denied for user 'username'@'localhost' to database 'mydb' It does not give me an error when I remove (it gives me a plain blank white page, which I am assuming it is suppose to do since I'm not calling for anything to appear, just to connect): if (mysql_query("CREATE DATABASE tainbfly_mydb",$con)) { echo "Database created"; } else { echo "Error creating database: " . mysql_error(); } Though once it is added into the coding, it gives me the error stated above. I feel like an idiot, getting two steps into a tutorial and already running into problems. I've tried going ahead and creating the db is my cpanel and assigning it a password and username (of course changing it in the proper areas in my coding), tried removing somethings, ect. but to no avail I have had no success. Any help would be much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/39888-access-denied/ Share on other sites More sharing options...
Yesideez Posted February 24, 2007 Share Posted February 24, 2007 When you created the user "username" did you grant it 'create access' to create tables? If you can't remember try making another user and grant it complete access over the database and try again. Quote Link to comment https://forums.phpfreaks.com/topic/39888-access-denied/#findComment-193246 Share on other sites More sharing options...
VMinder Posted February 25, 2007 Author Share Posted February 25, 2007 Yes I did, I even tried creating a different username and password just now but it wont let me grant access to the username unless I assign it a database. The database is not created yet because that is where I am getting the error. Quote Link to comment https://forums.phpfreaks.com/topic/39888-access-denied/#findComment-193315 Share on other sites More sharing options...
Yesideez Posted February 25, 2007 Share Posted February 25, 2007 Not sure on this one myself as I've always created databases via phpMy Admin - sorry! Quote Link to comment https://forums.phpfreaks.com/topic/39888-access-denied/#findComment-193325 Share on other sites More sharing options...
fenway Posted February 26, 2007 Share Posted February 26, 2007 Sounds like a grant permisson issue. Quote Link to comment https://forums.phpfreaks.com/topic/39888-access-denied/#findComment-194445 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.