...

View Full Version : Blank screen, nothing shows up.



Millenia
08-12-2008, 08:21 PM
I am a PHP newbie, as you know from my 'other thread', and I am working on a Blogging system for myself. Before I made a change to it, it displayed up to 6 posts in correct order, in a nice layout. However, the problem has started when I did something else. I am trying to make the header of the post, link to a page. On this page is that article, but on it's own. For each article, the page will be different. However when I come to test it, my page is just blank. I don't understand what happened or how to fix it, so can anyone give me guidance?


<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Description" content=" " />
<meta name="Keywords" content=" " />

<title>My Blog</title>
<link href="style.css" rel="stylesheet" type="text/css" />

</head>

<body>

<?php

error_reporting(E_ALL);

define('IN_BLOG', true);
require_once "config.php";

$sql = mysql_connect( $mysqlHost, $mysqlUsername, $mysqlPassword) or die(mysql_error());
mysql_select_db($mysqlDatabase, $sql) or die(mysql_error());

$result = mysql_query("SELECT * FROM blog_posts ORDER BY timestamp desc limit 6;
") or die(mysql_error());

$sqlCheck = mysql_query("SELECT * FROM blog_posts WHERE id='".$_GET['id']."'") or die(mysql_error());
$sqlCheck = mysql_num_rows($sqlCheck) or die(mysql_error());
$sqlRow = mysql_fetch_array($sqlCheck) or die(mysql_error());

if( !isset( $_GET['view'] ) && !isset( $_GET['id'] ))
{

while ( $row = mysql_fetch_array( $result ) )
{
echo "<h2><a href=\"index.php?view=post&amp;id=". $row['id'] . "\">" . $row['title'] . "</a></h2>" . "<p>" . $row['content'] . "</p><p><small>Posted by - <b>" .$row['author']. "</b> - on the date -<b>" . substr($row['timestamp'], -19, 11) .".</b></p></small>";
}

}else{

echo "<h2><a href=\"index.php?view=post&amp;id=". $sqlRow['id'] . "\">" . $sqlRow['title'] . "</a></h2>" . "<p>" . $sqlRow['content'] . "</p><p><small>Posted by - <b>" .$sqlRow['author']. "</b> - on the date -<b>" . substr($sqlRow['timestamp'], -19, 11) .".</b></p></small>";

}
?>
</body>
</html>

If you need any more code, let me know.

Thanks

Brandoe85
08-12-2008, 08:39 PM
Here is something I found awhile back on php.net under the error reporting page:


I had the problem that if there was an error, php would just give me a blank page. Any error at all forced a blank page instead of any output whatsoever, even though I made sure that I had error_reporting set to E_ALL, display_errors turned on, etc etc. But simply running the file in a different directory allowed it to show errors!

Turns out that the error_log file in the one directory was full (2.0 Gb). I erased the file and now errors are displayed normally. It might also help to turn error logging off.
Check into that for error reporting. To avoid having to escape double quotes in your html - use single quotes in your echos. Just remember, anything within single quotes is treated as a literal; php only interpolates variables in double quotes.

So,


echo '<a href="someurl.php">' . $someVar . '</a>';

Is much easier to maintain then escaping quotes.
Good luck;

CFMaBiSmAd
08-12-2008, 09:13 PM
When learning php, developing php code, or debugging php code, set display_errors on and error_reporting to E_ALL in your php.ini (stop and start your web server to get any changes made to php.ini to take effect) or in a .htaccess file to get php to help you. Fatal parse errors will prevent your code from executing so anything you do in your script to change these settings will have no effect if you are getting a fatal parse error (and for some buggy versions of php for a fatal runtime error.)

In your code, only mysql_connect(), mysql_select_db(), and mysql_query() cause mysql_error() to be set. Putting an or die(mysql_error()) on a mysql_num_rows() or a mysql_fetch_array() statement is meaningless because those two statements don't set mysql_error() and the die() will produce no output when either of those statements return a false or a value that is equal to false.

Millenia
08-12-2008, 09:21 PM
Right, heres the error:


[Tue Aug 12 21:26:00 2008] [error] PHP Notice: Undefined index: id in /home/jonny/public_html/index.php on line 28

and line 28 is this bit


$sqlCheck = mysql_query("SELECT * FROM blog_posts WHERE id='".$_GET['id']."'") or die(mysql_error());

Fou-Lu
08-13-2008, 12:18 AM
That is a notice, not exactly an error. This will not stop you're script from working. That is not what is causing an error, but it is possible that you're code executes fine with no results. Best thing to do is check you're source for this, if you have a <body></body></html> block, you're file is correct.
Now, on to you're actual code.
This: $sqlCheck = mysql_num_rows($sqlCheck) ; overwrites you're $sqlCheck query resource. This will cause
$sqlRow = mysql_fetch_array($sqlCheck); to fail. I'd put this as a prime suspect to the failure of you're script.
I'd combine the query into one, using $_GET['id'] as the condition only if it exists:


$sQry = "SELECT * FROM blog_posts";
if (isset($_GET['id']))
{
$sQry .= " WHERE `id` = " . (int)$_GET['id'];
}
$obQry = mysql_query($sQry) || die (sprintf("Error (%s): %s\n", mysql_errno(), mysql_error()));
if (mysql_num_rows($obQry) <= 0)
{
printf("No Results.");
}
else
{
while ($row = mysql_fetch_array($obQry))
{
...
}
}

Millenia
08-13-2008, 08:56 AM
That must be the problem, but I am lousy at PHP, so can you tell me what is wrong with my 'attempt'?


<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Description" content=" " />
<meta name="Keywords" content=" " />

<title>My Blog</title>
<link href="style.css" rel="stylesheet" type="text/css" />

</head>

<body>

<?php

error_reporting(E_ALL);

define('IN_BLOG', true);
require_once "config.php";

$sql = mysql_connect( $mysqlHost, $mysqlUsername, $mysqlPassword) or die(mysql_error());
mysql_select_db($mysqlDatabase, $sql) or die(mysql_error());

$result = mysql_query("SELECT * FROM blog_posts ORDER BY timestamp desc limit 6;
") or die(mysql_error());

if (isset($_GET['id']))
{
$result .= " WHERE `id` = " . (int)$_GET['id'];
}
$obQry = mysql_query($result) || die (sprintf("Error (&#37;s): %s\n", mysql_errno(), mysql_error()));
if (mysql_num_rows($obQry) <= 0)
{
printf("No Results.");
}
else
{
while ($row = mysql_fetch_array($obQry))
{
echo "<h2><a href=\"index.php?view=post&amp;id=". $row['id'] . "\">" . $row['title'] . "</a></h2>" . "<p>" . $row['content'] . "</p><p><small>Posted by - <b>" .$row['author']. "</b> - on the date -<b>" . substr($row['timestamp'], -19, 11) .".</b></p></small>";
}
}

?>
</body>
</html>I went wrong trying to impliment your script into mine, heres some errors:


[Wed Aug 13 08:51:56 2008] [error] PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/jonny/public_html/index.php on line 34Oh and by the way, try and remember I only have PHP 4.3, it's a nuisance but I can't help it.

Fou-Lu
08-13-2008, 07:07 PM
This blocks is querying a query. $result should be a string, and then rolled into a query. Order and Limit also needsto be the LAST items in the query:


$result = "SELECT * FROM blog_posts";

if (isset($_GET['id']))
{
$result .= " WHERE `id` = " . (int)$_GET['id'];
}
$result .= " ORDER BY timestamp desc limit 6";

$obQry = mysql_query($result) || die (sprintf("Error (%s): %s\n", mysql_errno(), mysql_error()));
if (mysql_num_rows($obQry) <= 0)
{
printf("No Results.");
}
else
{
while ($row = mysql_fetch_array($obQry))
{
echo "<h2><a href=\"index.php?view=post&amp;id=". $row['id'] . "\">" . $row['title'] . "</a></h2>" . "<p>" . $row['content'] . "</p><p><small>Posted by - <b>" .$row['author']. "</b> - on the date -<b>" . substr($row['timestamp'], -19, 11) .".</b></p></small>";
}
}

Try that.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum