Jump to content


Can't Use PHP to create table in MySQL

  • Please log in to reply
4 replies to this topic

#1 jawinn

  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 01 October 2006 - 06:28 PM

I'm trying to connect to a Godaddy MySQL DB using PHP. This is not a remote connection. This is on a shared account. Here is the code I'm trying to use. I have to be missing something.


// set your infomation.

// connect to the mysql database server.
$link_id = mysql_connect ($hostname, $username, $password);
echo "success in database connection.";

// select the specific database name we want to access.
if (!mysql_select_db($dbname)) die(mysql_error());
echo "success in database selection.";

// add a table to the selected database
$result="CREATE TABLE address_book (first_name VARCHAR(25), last_name VARCHAR(25), phone_number VARCHAR(15))";
if (mysql_query($result)){
echo "success in table creation.";
} else {
echo "no table created.";


I keep getting in the browser:
success in database connection.Access denied for user: 'name@%' to database 'dbname_dbname'

Any help is much appreciated.

#2 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 01 October 2006 - 07:47 PM

I don't know how much help I can be -- you don't seem to have the right credentials.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 nickholt1972

  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationBury, Lancs, UK

Posted 02 October 2006 - 12:04 PM

I think this line is causing you problems, I can't see the point of it. All it seems to do is to take your database connection name and screw it up.


My advice is to delete this line completely.

Nick Holt - Future Guru

#4 Daniel0

  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 02 October 2006 - 03:46 PM

You do not have the required permissions to access the database dbname_dbname

#5 jawinn

  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 02 October 2006 - 06:40 PM

Thanks for the quick responses guys.  It turns out that I was confusing my DB name for the table name.  I was using the DB name for both.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users