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
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.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.