Solved

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

Posted on 2014-07-20
14
593 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 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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 110

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

705 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