?
Solved

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

Posted on 2014-07-20
14
Medium Priority
?
599 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
  • +1
14 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 1080 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 1080 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 1080 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 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 920 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 84

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 111

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
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…
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…
Suggested Courses

752 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