Solved

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

Posted on 2014-07-20
14
564 Views
Last Modified: 2014-07-21
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
0
Comment
Question by:Dov_B
  • 6
  • 5
  • 2
  • +1
14 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 270 total points
ID: 40208087
$con=mysqli_connect("localhost.com","d","scores123!");

Is localhost.com what you really have there? If so that is wrong - unless your domain really is localhost.com, normally it would be just

localhost
or
127.0.0.1
0
 

Author Comment

by:Dov_B
ID: 40208091
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'
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 270 total points
ID: 40208095
Are you sure you have the username and password correct?
Not sure how GoDaddy works but you probably need to add a new database through their control panel. Your mysql user account will not have permissions to do it from php

http://support.godaddy.com/help/article/36/creating-mysql-or-sql-server-databases-for-your-hosting-account
0
 

Author Comment

by:Dov_B
ID: 40208099
oh ok how do I create a table in a databse that already exists
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 270 total points
ID: 40208104
0
 

Author Comment

by:Dov_B
ID: 40208107
<?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
0
 
LVL 58

Expert Comment

by:Gary
ID: 40208110
Check your username and password are correct
Whats the exact error message?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:Dov_B
ID: 40208112
Failed to connect to MySQL: Access denied for user 'd2'@'localhost' (using password: YES)
0
 
LVL 58

Expert Comment

by:Gary
ID: 40208117
Then the username is wrong.
0
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 230 total points
ID: 40208124
You need to go to your hosting control panel and find out what the proper credentials are to access your database.  I know for certain that it is Not going to be at 'localhost' because Godaddy doesn't do that.  They have dedicated MySQL servers that are on other machines.  'phpMyAdmin' on your hosting account is the best way to see what you have and to create new tables.
0
 

Author Comment

by:Dov_B
ID: 40208126
2014-07-20-22-16-22-cPanel-X.pnglook ther I am
0
 
LVL 58

Expert Comment

by:Gary
ID: 40208127
Dave is probably right about the hostname - I don't know
http://support.godaddy.com/help/article/3323/locating-your-database-connection-strings
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40208130
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'.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40208726
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.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This video teaches users how to migrate an existing Wordpress website to a new domain.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now