Home  |  About  | Last |  Submit  |  Contact
AllQuests.com




Previous Question:  Making HTML Smaller  HTML and XHTMLNext Question:  PHP script needs minor tweeking if it is possible  PHP
Question Blank page displaying ( SitePoint Forums PHP )
Updated: 2010-07-21 05:55:04 (17)
Blank page displaying

hey sitepointers,

im am currently creating a script to display articles i have the page which lists all the articles but then when i click on the link it takes me to the article in full, but i seem to be getting a blank page, this is the script i am using.

PHP Code:

<?php
include ('mysql_connect.php');
$query = "SELECT id, title, author, authoremail, preview, category, description, post,
DATE_FORMAT(date, '%M %d, %Y') as sd
FROM articles_posts
WHERE nid = $title"
;

if (isset(
$_GET['id'])) {
$id = $_GET['id'];
} else {
echo
'Please select a news post to view the comments.';
exit();
}

$result = @mysql_query($query);
if (
$result) {
while (
$row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo
"<div class=article><h2><a href=viewarticle.php?id=".$row['id'].">".$row['title']."</a></h2>
Posted By "
.$row['author'].", ".$row['sd']."
<img src="
.$row['preview']." class=\"floatLeft\" />
<p>"
.$row['description']."</p></div>";
}
}
?>
but i dont seem to be able to find why it isnt displaying, any help would be greatfull.

Answers: Blank page displaying ( SitePoint Forums PHP )
Blank page displaying

A while loop executes 0 or more times. The only place your script would produce output is if the while loops runs.

You need to do some basic debugging.

Turn up error reporting when debugging.
PHP Code:

// top of your scripts

ini_set('display_errors', 1);
error_reporting(E_ALL);
Ditch the @ operator, it silences errors. You shouldnt use this at all.

Use var_dump() on all of your variables to make sure they contain the value you think they do.

crmalibu

Blank page displaying

is $title defined?

Are there rows in the table?

If not, set $title to what it's supposed to be and add rows to the table.

If that isn't the case, try this (it should display errors - thats a good thing because it tells you what you've done wrong):
PHP Code:

<?php

error_reporting
(E_ALL);
ini_set('display_errors', 2);
include (
'mysql_connect.php');
$query = "SELECT id, title, author, authoremail, preview, category, description, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM articles_posts WHERE nid = {$title}";
if (isset(
$_GET['id'])) {
    
$id = $_GET['id'];
} else {
    echo
'Please select a news post to view the comments.';
    exit();
}
$result = mysql_query($query) or die(mysql_error());
while (
$row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo <<<HTML
    <div class=article>
        <h2>
            <a href="viewarticle.php?id=
{$row['id']}">
                
{$row['title']}
            </a>
        </h2>
        <p>Posted By
{$row['author']}, {$row['sd']}</p>
        <img src="
{$row['preview']}" class="floatLeft" />
        <p>
{$row['description']}</p>
    </div>
HTML;
}
?>

Jake Arkinstall

Blank page displaying

ok im now using the script arkinstall provided, ive changed it to disply using the id instead of the title, i do have rows in my database but it is still displaying nothing but has this error showing up

Quote:
Notice: Undefined variable: title in /home/ltjfansi/public_html/webtoolsking/v3/articles/viewarticle.php on line 41
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
line 41 would be the blank space under that line of code.

Quote:
ini_set('display_errors', 2);

ltjfansite

Blank page displaying

There you go then

What's $title supposed to be? 'Cus you haven't set it.

Jake Arkinstall

Blank page displaying

its supposed to be the title of the article which its grabbing out of the database. i dont get whats missing

ltjfansite

Blank page displaying

Well, you haven't grabbed the title out of the database. Can you show us the whole PHP file?

But guessing it's the ID given to the page that you're after, try this:
PHP Code:

<?php 

error_reporting
(E_ALL);
ini_set('display_errors', 2);
include (
'mysql_connect.php');
if (isset(
$_GET['id'])) {
    
$id = (int)$_GET['id'];
} else {
    echo
'Please select a news post to view the comments.';
    exit();
}
$result = mysql_query("SELECT id, title, author, authoremail, preview, category, description, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM articles_posts WHERE id = {$id}") or die(mysql_error());
while (
$row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo <<<
HTML
    
<div class=article>
        <
h2>
            <
a href="viewarticle.php?id={$row['id']}">
                {
$row['title']}
            </
a>
        </
h2>
        <
p>Posted By {$row['author']}, {$row['sd']}</p>
        <
img src="{$row['preview']}" class="floatLeft" />
        <
p>{$row['description']}</p>
    </
div>
HTML;
}
?>

Jake Arkinstall

Blank page displaying

PHP Code:

<?php
$thisPage
= "articles";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Web Tools King - Articles</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css"
    media="screen" title="User
Defined Style" href="../css/<?php echo
(!
$sitestyle)?'blue':$sitestyle ?>.css" />
</head>
</head>



<?php

include '../head.php';

?>

<div id="submenu">

<a href="../">Home</a> > <a href="../articles/">Articles</a> > <?php echo "".$row['title'].""; ?>

</div>




<?php

error_reporting
(E_ALL);

ini_set('display_errors', 2);

include (
'mysql_connect.php');

$query = "SELECT id, title, author, authoremail, preview, category, description, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM articles_posts WHERE nid = {$title}";

if (isset(
$_GET['id'])) {

    
$id = $_GET['id'];

} else {

    echo
'Please select a news post to view the comments.';

    exit();

}

$result = mysql_query($query) or die(mysql_error());

while (
$row = mysql_fetch_array($result, MYSQL_ASSOC)) {

    echo <<<HTML

    <div class=article>

        <h2>

            <a href="viewarticle.php?id=
{$row['id']}">

                
{$row['title']}

            </a>

        </h2>

        <p>Posted By
{$row['author']}, {$row['sd']}</p>

        <img src="
{$row['preview']}" class="floatLeft" />

        <p>
{$row['description']}</p>

    </div>

HTML;
}

?>

include '../foot.php';

?>
thats the whole file.

ltjfansite

Blank page displaying

Thought so. Look up ^

Jake Arkinstall

Blank page displaying

ok i now removed the <?php echo $title; ?> form the submenu part, and the error is now on line 40

ltjfansite

Blank page displaying

$title needs to be set before you use it. You can't use it before setting it - remember, scripts work a line at a time.

PHP Code:

<?php

error_reporting
(E_ALL);
ini_set('display_errors', 2);
include (
'mysql_connect.php');
$thisPage = "articles";
$style = isset($sitestyle) ? $sitestyle : 'blue';
echo <<<TOP
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Web Tools King - Articles</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <link rel="stylesheet" type="text/css" media="screen" title="User Defined Style" href="../css/
{$style}.css" />
    </head>
TOP;
include
'../head.php';
if (isset(
$_GET['id'])) {
    
$id = (int)$_GET['id'];
} else {
    echo
'Please select a news post to view the comments.';
    exit();
}
$query = "SELECT id, title, author, authoremail, preview, category, description, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM articles_posts WHERE id = {$id}";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
echo <<<HTML
    <div id="submenu">
        <a href="../">Home</a> > <a href="../articles/">Articles</a> >
{$row['title']}
    </div>
    <div class=article>
        <h2>
            <a href="viewarticle.php?id=
{$row['id']}">
                
{$row['title']}
            </a>
        </h2>
        <p>Posted By
{$row['author']}, {$row['sd']}</p>
        <img src="
{$row['preview']}" class="floatLeft" />
        <p>
{$row['description']}</p>
    </div>
HTML;
}
include
'../foot.php';
?>

Jake Arkinstall

Blank page displaying

ok thanks you, but now

Parse error: syntax error, unexpected '}' in /home/ltjfansi/public_html/webtoolsking/v3/articles/viewarticle.php on line 80

which this code

<img src="{$row['preview']}" class="floatLeft" />

<p>{$row['description']}</p>



ltjfansite

Blank page displaying

Make sure there aren't any spaces after these commands:
echo <<<TOP
echo <<<HTML

Copying code from the forums sometimes adds spaces at the end of each line.

Jake Arkinstall

Blank page displaying

no spaces there anymore and the error line has dropped to 78

ltjfansite

Blank page displaying

There's a line 78? What is it? (My code was only 43 lines)

Jake Arkinstall

Blank page displaying

it was the same line as before

PHP Code:

<img src="{$row['preview']}" class="floatLeft" />

        <
p>{$row['description']}</p>

ltjfansite

Blank page displaying

Try removing the brace } from the second-to-last line of the file.

Jake Arkinstall

Blank page displaying

that has got rid of that error, but now it doesnt display any of the data, it had the text there what isnt generated by the database, but thats all.

EDIT all fixed, thanks for the help dude.

ltjfansite

Previous Question:  Making HTML Smaller  SitePoint Forums  HTML and XHTMLNext Question:  PHP script needs minor tweeking if it is possible  SitePoint Forums  PHP

- Source: Blank page displaying SitePoint Forums PHP
- Previous Question: Making HTML Smaller SitePoint Forums HTML and XHTML
- Next Question: PHP script needs minor tweeking if it is possible SitePoint Forums PHP