This is the code I am having trouble with:

<?php

mysql_connect('localhost', 'username', 'password') or die(mysql_error());
mysql_select_db('database') or die(mysql_error());

$posts = mysql_query("SELECT * FROM  `wp_DevBlogposts` ORDER BY  `wp_DevBlogposts`.`post_date` DESC LIMIT 2") or die(mysql_error());

while($row = mysql_fetch_array($posts)){

$post_name = $row['post_title']; // Post Name/Title
$post_content = $row['post_content']; // Post Content
$url = $row['guid']; // Post URL

}
?>
<!DOCTYPE html>

<html>

<body>

    <table>
        <tr>
            <td>
            <b><a href='$url'><?php echo $post_name; ?></a></b>
            </td>
            <td>
            <b><?php echo $post_content; ?></b>
            </td>
        </tr>
    </table>
    <br />
</body>

</html>

This code is completely valid, it is constantly spitting up this error:

Access denied for user 'username'@'localhost' to database 'database_database'

The problem is that I can connect to all of the other tables but this one keeps giving me that error. I don't know why I would be able to connect to all the other tables but this one. Thanks for helping!

Recommended Answers

All 4 Replies

Member Avatar for LastMitch

@Djmann1013

The problem is that I can connect to all of the other tables but this one keeps giving me that error. I don't know why I would be able to connect to all the other tables but this one.

It means that username has not been grant access to that db. Did you give this username perrmission to access the db? If not then you should gave that username access.

commented: Thanks! +2
commented: To Rectify what some retard did to LastMitch +0

I am using a webhost called x10Hosting. I am not sure if I can grant access to the username. If I can, then what do I do?

Thanks

Thanks you helped!

Member Avatar for LastMitch

@Djmann1013

I am using a webhost called x10Hosting. I am not sure if I can grant access to the username. If I can, then what do I do?

You figure it out?

You know there alot of host server like bluehost or godaddy or xhosting. It's really hard to give you a straight answer about:

Access denied for user 'username'@'localhost' to database 'database_database'

I only gave you a outline of the issue. In order to fixed that issue is to let the username access.

But I'm glad you solve it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.