Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have the following php code:

<?php
$con=mysqli_connect("server19.0hosting.org","user","password","dbname");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM dbtable");

echo "<table border='1'>
<tr>
<th>Nume</th>
<th>Teme facute</th>
<th>Teme nefacute</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Nume'] . "</td>";
echo "<td>" . $row['Teme facute'] . "</td>";
echo "<td>" . $row['Teme nefacute'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>

When I run it online, I get the following message:

Warning: mysqli_connect(): (28000/1045): Access denied for user 'u536268762_alex'@'srv19.main-hosting.com' (using password: YES) in /home/u536268762/public_html/index.html on line 2 Failed to connect to MySQL: Access denied for user 'u536268762_alex'@'srv19.main-hosting.com' (using password: YES)

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /home/u536268762/public_html/index.html on line 9

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/u536268762/public_html/index.html on line 18

Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in /home/u536268762/public_html/index.html on line 28

Can please anyone help me? Also, is it the right hostname the one I wrote there before user?

share|improve this question
1  
So how can we help you? Provide a password? Write a letter to a support? – u_mulder Dec 13 '15 at 17:13
    
what should i change in order to make it display the right thing? i mean the content of the table? – Alex Resiga Dec 13 '15 at 17:14
    
check your connection parameters are correct.. – Sugumar Venkatesan Dec 13 '15 at 17:15
    
@SugumarVenkatesan how can i do that? i am a beginner and that's why i'm asking – Alex Resiga Dec 13 '15 at 17:16
up vote 1 down vote accepted

Although you should have given some host information, I'll assume certain things (if necessary) and type in something here.

  1. If your php script is on the same server, which has the database (the most common thing with all shared services) then you can simply use localhost, e.g;

    $con=mysqli_connect("localhost","user","password","dbname");

  2. The possible reasons for Access Denied are:

    • Username or Password is wrong.
    • Username is not given permissions to connect to the database. (You usually do this while creating a new database.)
share|improve this answer
    
i've tried using the localhost instead but i'm getting the same error – Alex Resiga Dec 13 '15 at 17:35
    
Yes you get it because of the wrong credentials... Where is your website hosted? local or web cpanel? – Huzaib Shafi Dec 13 '15 at 17:36
    
i found the hostname in the MySQL section of my hoster. i'm using cpanel hosting from hourb.thanks for your help – Alex Resiga Dec 13 '15 at 17:40

You have an error in this statement.

mysqli_connect("server19.0hosting.org","user","password","dbname");

mysli_connect("hostname", "username", "password", "databasename");

check this parameters are correct(check with the person or admin who gave you this details) server19.0hosting.org(hostname) is correct user(username) is correct password(password) is correct dbname(databasename) is correct

share|improve this answer
    
how can i find my hostname? i mean is it the site's hostname? – Alex Resiga Dec 13 '15 at 17:26
    
it's where you database server is running – Sugumar Venkatesan Dec 13 '15 at 17:26
    
I think you need to ask your hosting provider for this connection parameters – Sugumar Venkatesan Dec 13 '15 at 17:29
    
oh i found what hostname i was supposed to write. thanks for the help – Alex Resiga Dec 13 '15 at 17:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.