Link to home
Start Free TrialLog in
Avatar of Dov_B
Dov_B

asked on

I need help getting a php file to run on my website

I have a website hosted by godaddy having difficulty getting php to interact with a mysql database on my site
<?php
$con=mysqli_connect("localhost.com","d","scores123!");
// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// Create database
$sql="CREATE DATABASE my_db";
if (mysqli_query($con,$sql)) {
  echo "Database my_db created successfully";
} else {
  echo "Error creating database: " . mysqli_error($con);
}
?>

Open in new window

I placed it this code in a file and place it a folder on my website but it takes a million years for it to run and then it errors out
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dov_B
Dov_B

ASKER

Thanks so much I got closer after your correction I got the follwing error
Error creating database: Access denied for user 'd2'@'localhost' to database 'my_db'
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dov_B

ASKER

oh ok how do I create a table in a databse that already exists
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dov_B

ASKER

<?php
// Create connection
$con=mysqli_connect("localhost","d2","scores123!","scores2");

// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>

Open in new window

error acsses denied
Check your username and password are correct
Whats the exact error message?
Avatar of Dov_B

ASKER

Failed to connect to MySQL: Access denied for user 'd2'@'localhost' (using password: YES)
Then the username is wrong.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dov_B

ASKER

User generated imagelook ther I am
I'm not familiar with that screenshot.  That does not exist on either of my Godaddy hosting accounts.  You need to get the correct hostname, either by IP address or name, to put in your connections statement.

I've never seen Cpanel or Plesk on Godaddy hosting so you might have that.  The link that Gary shows says Cpanel does use 'localhost'.
This is a basic and fundamental question, one that almost every single GoDaddy client would face.  As such it would have been asked of GoDaddy thousands of times.  Have you called GoDaddy technical support and asked them to send you the link to the standard answer they give to new clients?  If not, please do that!  And then post the link here so we can see what they gave you for guidance.  We can probably fill in any blanks that remain unclear after you've seen the hosting company's recommendation.

If they can't help, you might want to consider moving to another hosting company.  I use and am pleased to recommend ChiHost.com.  I have also had good experiences with Hostagator and LiquidWeb.  I do not recommend either GoDaddy or SiteGround.  But YMMV and GoDaddy may be able to help you.