Solved

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

Posted on 2014-07-20
14
570 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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 

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 83

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 83

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

919 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

21 Experts available now in Live!

Get 1:1 Help Now