Jump to content

Help with PHP index file


Far Cry

Recommended Posts

<?php
include_once 'connection.php';

$query = "Select * FROM news WHERE Page = 1";
$result = mysql_query($query);

while($post = mysql_fetch_array($result)) {
echo "<h1>" . $row['Post_Title'] . "</h1><br>";
echo "<h3>" . $row['Post_Author'] . "</h3><br>";
echo "<p>" . $row['Post_Content'] . "</p>";
}
?>

 

 

Here is the code from the index file, however when I load this page in my browser in comes out blank, when it is supposed to echo the data from my database.

Can anyone help? Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/205457-help-with-php-index-file/
Share on other sites

Take a look in your error log.  Could be any number of things related to your database connection.  We don't have enough information but I would make the general comment that your code doesn't check for errors.  For example, you do a mysq_query() and store the result to $result, but don't check to see if $result if valid before you try and fetch.

 

 

Change

<?php
while($post = mysql_fetch_array($result)) {
echo "<h1>" . $row['Post_Title'] . "</h1><br>";
echo "<h3>" . $row['Post_Author'] . "</h3><br>";
echo "<p>" . $row['Post_Content'] . "</p>";
}
?>

to

<?php
while($row = mysql_fetch_array($result)) {
echo "<h1>" . $row['Post_Title'] . "</h1><br>";
echo "<h3>" . $row['Post_Author'] . "</h3><br>";
echo "<p>" . $row['Post_Content'] . "</p>";
}
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.