I'm new to PHP and MySQL and I'm trying to pull data from individual columns to input into my website. Now, I've seen tons of examples; however, I feel like I must be missing something simple because I can't seem to get it to work. How do I actually pull individual columns and do this repeatedly for everything in that particular table?
Here is my PHP function I'm trying to run:
getPosts();
function getPosts() {
// Create connection
$link = new mysqli($servername, $username, $password, $dbname);
$sql = 'SELECT
title,
date,
body,
author,
owner
FROM
posts';
$results = $link->query($sql);
echo "<div class='post'>
<div class='post-title'>
<span class='post-heading'>" . $row["title"] .
"</span><span class='post-date'>" . $row["date"] .
"</span>
</div>
<div class='post-body'>
<p>" . $row["body"] . "</p>
</div>
<div class='post-footer'>
<hr/>
<span class='author-note'><span class='glyphicon
glyphicon-triangle-top'></span> <i>Posted by
<a href='#'>" . $row["author"] . "</a> | Owned
by <a href='#'>" . $row["owner"] . "</a></i></span>
</div>
</div>";
$link->close();
}
And then I'm getting these errors when I run this:
Warning: mysqli::mysqli(): (28000/1045):
Access denied for user 'root'@'localhost' (using password: NO)
in /home/mynameis/public_html/bardassets/main.php on line 13
Warning: mysqli::query(): Couldn't fetch mysqli in
/home/mynameis/public_html/bardassets/main.php on line 24
Warning: mysqli::close(): Couldn't fetch mysqli in
/home/mynameis/public_html/bardassets/main.php on line 41
I guess I just want to know what key part I'm missing here.