Solved

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

Posted on 2014-07-20
14
586 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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
 

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 109

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

790 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