Jump to content

access denied?


VMinder

Recommended Posts

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/39888-access-denied/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.