Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    May 2008
    Location
    Lost in Localhost...
    Posts
    702
    Thanks
    3
    Thanked 43 Times in 42 Posts

    Blank screen, nothing shows up.

    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?

    PHP Code:
    <!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'], -1911) .".</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'], -1911) .".</b></p></small>";

    }
    ?>
    </body>
    </html>
    If you need any more code, let me know.

    Thanks

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Here is something I found awhile back on php.net under the error reporting page:
    Quote Originally Posted by http://www.php.net
    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,
    PHP Code:
    echo '<a href="someurl.php">' $someVar '</a>'
    Is much easier to maintain then escaping quotes.
    Good luck;

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    Regular Coder
    Join Date
    May 2008
    Location
    Lost in Localhost...
    Posts
    702
    Thanks
    3
    Thanked 43 Times in 42 Posts
    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

    PHP Code:
    $sqlCheck mysql_query("SELECT * FROM blog_posts WHERE id='".$_GET['id']."'") or die(mysql_error()); 
    Last edited by Millenia; 08-12-2008 at 09:31 PM.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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:
    PHP Code:
    $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))
        {
            ...
        }

    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    Regular Coder
    Join Date
    May 2008
    Location
    Lost in Localhost...
    Posts
    702
    Thanks
    3
    Thanked 43 Times in 42 Posts
    That must be the problem, but I am lousy at PHP, so can you tell me what is wrong with my 'attempt'?

    PHP Code:
    <!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 (%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'], -1911) .".</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 34
    Oh and by the way, try and remember I only have PHP 4.3, it's a nuisance but I can't help it.
    Last edited by Millenia; 08-13-2008 at 09:05 AM.

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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:
    PHP Code:
    $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'], -1911) .".</b></p></small>";
        }

    Try that.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •