I was trying to make a VERY simple CMS for a website for a personal project. It’s my first time using MySQL, and one of my first using PHP, so it’s kind of a learning experience. According to everybody I’ve asked, though, this should work. However, all it outputs is the <h1></h1>. I’ve checked everything on my database and table, the column names are right. I’m not trying to make anything to add to the database just yet. I just want to be able to read, and even a simple proof-of-concept isn’t working.
If it matters, I’m using 000webhost for my web hosting.
<?php
$mysql_host = "****";
$mysql_database = "****";
$mysql_user = "sql_blog";
$mysql_password = "*****";
$link = mysql_connect($mysql_host, $mysql_user, $mysql_password);
if (!mysql_select_db($mysql_database, $link)) {
echo 'Database error';
exit;
}
$sql_statement = ('SELECT * FROM Blog_Entries');
$result = mysql_query($sql_statement);
while ($curr_row = mysql_fetch_assoc($result)) {
echo '<h1>' . $result['Title'] . '</h1>';
}
mysql_free_result($result);
?>
Most of that code is copied from http://guy-lecky-thompson.suite101.com/build-a-blog-or-cms-with-php-a55246 but like I said, it looks like it should work…
You have an error in your while loop.
Should be
When you iterate through the rows you need to use the row, not the pointer to the resultset.