SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php page now blank when browsed

    was bopping along following the tutorial (http://www.sitepoint.com/article/php...nstallation/4), substituting their joke
    database with my lost Pet database. Everything was great until the last step
    where you allow user to add and delete db rows. Now my page doesn't
    display anything! if you view the source, the body tags enclose nothing
    at all. Very sad. I even added a line of text, right after the open body
    tag, before i do any php. and still nothing displays. what am i doing wrong?

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Location
    edge of nowhere
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You probably have an error somewhere and display_errors is off. Check error_log and see what's going on.

    Better yet, do phpinfo(); in a separate file and see both the path to error_log, and if display_errors is off. Also post your code over here and somebody might spot your error.
    Programming boils down to three things: fast, good and cheap.
    Please pick two.

  3. #3
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    don't know where error_log is, so i'll go the post-the-code route. Hope you can help!

    note: the "we're at top" doesn't even display!

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <title>The TPPOA Pet Database</title> 
    <meta http-equiv="content-type" 
       content="text/html; charset=iso-8859-1" /> 
    </head> 
    <body> 
    <p>We're at top </p>
    <?php if (isset($_GET['addpet'])): // User wants to add a pet 
    ?> 
    echo <p>We are in add </p>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
    <label>Type your Species here:<br /> 
    <textarea name="species" rows="1" cols="40"> 
    </textarea>
    </label><br /> 
    <label>Is pet lost or found?:<br /> 
    <textarea name="status" rows="1" cols="40"> 
    </textarea>
    </label><br /> 
    <input type="submit" value="SUBMIT" /> 
    </form> 
    
    <?php else: // Default page display 
    echo <p>We are in default </p>
     // Connect to the database server 
     $dbcnx = @mysql_connect('mysql.thehostsrvr.com', 'login', 'passwd'); 
     if (!$dbcnx) { 
       exit('<p>Unable to connect to the ' . 
           'database server at this time.</p>'); 
     } 
    
     // Select the pet database 
     if (!@mysql_select_db('Pet')) { 
       exit('<p>Unable to locate the Pet ' . 
           'database at this time.</p>'); 
     } 
     
     // If a pet has been submitted, 
     // add it to the database. 
     if (isset($_POST['species','status'])) { 
       $species = $_POST['species']; 
       $status = $_POST['status'];
       $sql = "INSERT INTO Animal SET 
           Species='$species', 
           Status='$status'"; 
       if (@mysql_query($sql)) { 
         echo '<p>The animal has been added.</p>'; 
       } else { 
         echo '<p>Error adding submitted animal: ' . 
             mysql_error() . '</p>'; 
       } 
     } 
    
     // If a pet has been deleted, 
     // remove it from the database. 
     if (isset($_GET['deletepet'])) { 
       $petid = $_GET['deletepet']; 
       $sql = "DELETE FROM Animal 
           WHERE ID=$petid"; 
       if (@mysql_query($sql)) { 
         echo '<p>The animal has been deleted.</p>'; 
       } else { 
         echo '<p>Error deleting animal: ' . 
             mysql_error() . '</p>'; 
       } 
     } 
          
     echo '<p> Here are all the animals in our database: </p>'; 
    
     // Request the ID and text of all the pets 
     $result = @mysql_query('SELECT ID, Species, Status FROM Animal'); 
     if (!$result) { 
       exit('<p>Error performing query: ' . 
           mysql_error() . '</p>'); 
     } 
    
     // Display the text of each pet in a paragraph 
     // with a "Delete this pet" link next to each. 
     while ($row = mysql_fetch_array($result)) { 
       $petid = $row['ID']; 
       $Species = $row['Species']; 
       $Status = $row['Status'];
       echo '<p>' . $Species . ' ' . $Status
           ' <a href="' . $_SERVER['PHP_SELF'] . 
           '?deletepet=' . $petid . '">' . 
           'Delete this pet</a></p>'; 
     } 
    
     // When clicked, this link will load this page 
     // with the pet submission form displayed. 
     echo '<p><a href="' . $_SERVER['PHP_SELF'] . 
         '?addpet=1">Add a Pet!</a></p>'; 
    
    endif; 
    ?> 
    </body> 
    </html>

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2006
    Location
    Dundee, Scotland
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may or may not have an error_log file, it depends on the configuration.

    Your best bet would be if you have access to look into the raw http log files. This should show any errors that occurred when your script was being run.

  5. #5
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok...raw http logs. so, the php and webserver are on the remote server, not my pc. is this also where the raw logs are? do i need to request access from my provider?

  6. #6
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's no need to concern yourself with the logs. Turn error_reporting and display of errors on at the script level. Doing this for testing and debugging is much easier than using the log files. At the top of the script just put the following lines..

    PHP Code:
    ini_set('error_reporting',E_ALL);
    ini_set('display_errors','on'); 
    That will give you error reporting within the page, unless there is a real show stopper in the code.

  7. #7
    SitePoint Zealot
    Join Date
    Jul 2006
    Location
    Dundee, Scotland
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have just taken a proper look at your code and have found the following:-

    This should be changed:-

    PHP Code:
    echo <p>We are in default </p
    To this:-

    PHP Code:
    echo '<p>We are in default </p>'
    And this should be changed:-

    PHP Code:
     if (isset($_POST['species','status'])) { 
    to this:-

    PHP Code:
     if (isset($_POST['species']) && isset($_POST['status'])) { 
    This should be changed:-

    PHP Code:
       echo '<p>' $Species ' ' $Status
           
    ' <a href="' $_SERVER['PHP_SELF'] . 
    To this:-

    PHP Code:
       echo '<p>' $Species ' ' $Status.
           
    ' <a href="' $_SERVER['PHP_SELF'] . 
    These all caused syntax errors and you would have spotted it if you had error reporting enabled. Use the code Hammer65 posted at the top of any php script (within php tags).

    If you still have problems and nothing is displaying then you will need in my opinion to look into the raw http logs which are on the server (you may have access, you may not).

  8. #8
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I made the recommended changes, with no better luck. I also inserted the degugging lines, but i'm sure they're in the wroing place. I tried several locations without success. Could you tell me between which two lines to add them? The php script itself is split up into two or three sections on the web page. Also, where will the debug info display? On the page itself, when viewed?

    I appreciate your continued help!

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <title>The TPPOA Pet Database</title> 
    <meta http-equiv="content-type" 
       content="text/html; charset=iso-8859-1" /> 
    </head> 
    <body> 
    <p>We're at top </p>
    ini_set('error_reporting',E_ALL); 
    ini_set('display_errors','on');
    <?php if (isset($_GET['addpet'])): // User wants to add a pet 
    ?> 
    echo <p>We are in add </p>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
    <label>Type your Species here:<br /> 
    <textarea name="species" rows="1" cols="40"> 
    </textarea>
    </label><br /> 
    <label>Type your Status here:<br /> 
    <textarea name="status" rows="1" cols="40"> 
    </textarea>
    </label><br /> 
    <input type="submit" value="SUBMIT" /> 
    </form> 
    
    <?php else: // Default page display 
    echo '<p>We are in default </p>'
     // Connect to the database server 
     $dbcnx = @mysql_connect('mysql.thehostsrvr.com', 'login', 'password'); 
     if (!$dbcnx) { 
       exit('<p>Unable to connect to the ' . 
           'database server at this time.</p>'); 
     } 
    
     // Select the jokes database 
     if (!@mysql_select_db('Pet')) { 
       exit('<p>Unable to locate the Pet ' . 
           'database at this time.</p>'); 
     } 
     
     // If a pet has been submitted, 
     // add it to the database. 
     if (isset($_POST['species')) && (isset($_POST['status'])){ 
       $species = $_POST['species']; 
       $status = $_POST['status'];
       $sql = "INSERT INTO Animal SET 
           Species='$species', 
           Status='$status'"; 
       if (@mysql_query($sql)) { 
         echo '<p>The animal has been added.</p>'; 
       } else { 
         echo '<p>Error adding submitted animal: ' . 
             mysql_error() . '</p>'; 
       } 
     } 
    
     // If a pet has been deleted, 
     // remove it from the database. 
     if (isset($_GET['deletepet'])) { 
       $petid = $_GET['deletepet']; 
       $sql = "DELETE FROM Animal 
           WHERE ID=$petid"; 
       if (@mysql_query($sql)) { 
         echo '<p>The animal has been deleted.</p>'; 
       } else { 
         echo '<p>Error deleting animal: ' . 
             mysql_error() . '</p>'; 
       } 
     } 
          
     echo '<p> Here are all the animals in our database: </p>'; 
    
     // Request the ID and text of all the pets 
     $result = @mysql_query('SELECT ID, Species, Status FROM Animal'); 
     if (!$result) { 
       exit('<p>Error performing query: ' . 
           mysql_error() . '</p>'); 
     } 
    
     // Display the text of each pet in a paragraph 
     // with a "Delete this pet" link next to each. 
     while ($row = mysql_fetch_array($result)) { 
       $petid = $row['ID']; 
       $Species = $row['Species']; 
       $Status = $row['Status'];
       echo '<p>' . $Species . ' ' . $Status.
           ' <a href="' . $_SERVER['PHP_SELF'] . 
           '?deletepet=' . $petid . '">' . 
           'Delete this pet</a></p>'; 
     } 
    
     // When clicked, this link will load this page 
     // with the pet submission form displayed. 
     echo '<p><a href="' . $_SERVER['PHP_SELF'] . 
         '?addpet=1">Add a Pet!</a></p>'; 
    
    endif; 
    ?> 
    </body> 
    </html>

  9. #9
    Chessplayer kleineme's Avatar
    Join Date
    Apr 2004
    Location
    Germany
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    put them at the top of the script within PHP tags:

    PHP Code:
    <?php
    ini_set
    ('error_reporting',E_ALL); 
    ini_set('display_errors','on');
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    Never ascribe to malice,
    that which can be explained by incompetence.
    Your code should not look unmaintainable, just be that way.

  10. #10
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As recommended, I put the tags at the top of the doc, very first lines. Still nothing displays, no errors, no text.

    It seems this behavior (or lack thereof) started when i added the php if-then-else clause. Can any one see problems with that construction?

    But even then...i should have seen the "we are at top" statement, right?

  11. #11
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone have any other ideas? Getting deperate and dismayed here....

  12. #12
    Chessplayer kleineme's Avatar
    Join Date
    Apr 2004
    Location
    Germany
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know why you get no errors displayed. When I use your code I get two parse errors:

    a missing semicolon here:
    echo '<p>We are in default </p>';
    instead of
    echo '<p>We are in default </p>'

    missing brackets here:
    if (isset($_POST['species']) && isset($_POST['status'])){
    instead of
    if (isset($_POST['species')) && (isset($_POST['status'])){
    Never ascribe to malice,
    that which can be explained by incompetence.
    Your code should not look unmaintainable, just be that way.

  13. #13
    SitePoint Enthusiast wyte raven's Avatar
    Join Date
    Feb 2007
    Location
    England, High Wycombe Bucks
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo <p>We are in add </p
    Surely this line should be echoed within PHP tags, and also should look like:

    PHP Code:
    echo '<p>We are in add</p>'
    Wyte R@ven - Creator of the Rift

  14. #14
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If for some reason error reporting doesn't work for you, don't panic work through the code in a systematic fashion.

    Comment out all your code. One by one un-comment and test each section or block, using echo or var_dump to monitor what is happening. Once a section of code has passed the tests then move on to the next one. You will find your error.

    This is what you would normally do with a debugger, however I'm guessing that you probably don't have one.


Bookmarks

Posting Permissions

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