Jump to content

Can't Use PHP to create table in MySQL


jawinn

Recommended Posts

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.

<?php

// set your infomation.
$hostname='server.servername.net';
$username='name';
$password='password';
$dbname='dbname';

// 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.
$dbname=$username."_".$dbname;
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

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.