SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 31

Thread: Blank Page

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Blank Page

    I've just created the 'jokes.php' page from page 77 in 'Build your own database using php & mySql'. When i open the page using localhost it just displays a blank page. I've checked the code and it seems to all be correct, and localhost works with other files.

    Why would this be happening? Any ideas?

    Cheers

  2. #2
    SitePoint Evangelist djdykes's Avatar
    Join Date
    Feb 2005
    Location
    Chester, Cheshire
    Posts
    566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dude you wanna post your code?

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <body>

    <?php if (isset($_GET['addjoke'])): // User wants to add a joke
    ?>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <label>Type your joke herebr />
    <textarea name="joketext" rows="10" cols="40">
    </textarea></label><br />
    <input type="submit" value="SUBMIT" />
    </form>

    <?php else: // Default page display

    //Connect to the database server
    $dbcnx = @mysql_connect('localhost', 'root', 'mypasswd');
    if (!$dbcnx) {
    exit('<p>Unable to connect to the ' .
    'database server at this time.</p>');
    }

    //Select the jokes database
    if (!@mysql_select_db('ijdb')) {
    exit('<p>Unable to locate the joke ' .
    'database at this time.</p>');
    }

    //If a joke has been submitted,
    //add it to the database.
    if (isset($_POST['joketext'])) {
    $joketext = $_POST['joketext'];
    $sql = "INSERT INTO joke SET
    joketext='$joketext',
    jokedate=CURDATE()";
    if (@mysql_query($sql)){
    echo '<p>Your joke has been added.</p>';
    } else {
    echo '<p>Error adding submitted joke: ' .
    mysql_error() . '</p>';
    }
    }

    echo '<p>Here are all the jokes in our database/p>';

    //Request the text of all the jokes
    $result = @mysql_query('SELECT joketext FROM joke');
    if (!$result) {
    exit('<p>Error performing query: ' .
    mysql_error() . '</p>');
    }

    //Display the text of each joke in a paragraph
    while ($row = mysql_fetch_array($result)) {
    echo '<p>' . $row['joketext'] . '</p>';
    }

    //When clicked, this link will load this page
    //with the joke submission form displayed.
    echo '<p><a href="' . $_SERVER['PHP_SELF'] .
    '?addjoke=1">Add a joke!</a></p>';

    endif;
    ?>
    </body>

  4. #4
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's probably a typo in your code, so you can paste it here and we'll take a look. Also you should try to View Source the page and see if there are any errors hidden somewhere. Also you should find out where your errors are being sent...if not to screen, maybe to some error_log file.

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when i try to view source it shows no php at all, there's nothing between the body tags

  6. #6
    SitePoint Addict bkennedy's Avatar
    Join Date
    Aug 2004
    Location
    michigan
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the source of the generated page shows something like this...

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD>
    <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"></HEAD>
    <BODY></BODY></HTML>
    That means you have a syntax error in your code, and it stopped trying to display it. If it displays something like this...

    HTML Code:
    <body></body>
    Your code is fine, except it's just not receiving any results.
    In the first case, comment out large sections of your code (at first leaving just a few statements) until it displays something other that my first code block. Keep uncommenting sections until you narrow it down to where your problem is.
    If your case is the second one, where just the body tags are displaying, try putting echo statements in your code to track it's progress... like...

    echo "checking db";

    etc. That might give you a good clue as to what's going on.
    Either way, it wouldn't hurt to just put all of it inside the php tags and use print or echo statements to output the html. (But try the other things first.)
    ----------------
    bob.kennedy
    ----------------

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't have the closing Body tag:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>The Internet Joke Database</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>

    Could that be another problem?

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    check a couple of things:
    is this bit correct...
    PHP Code:
    <?php if (isset($_GET['addjoke'])): // User wants to add a joke
    ?>
    cos what this says to me is if the variable 'addjoke' is set, process the code . If not, dont do anything because there is nothing else to do on the page.

    If it is right, check that the variable is being passed properly.

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Addict bkennedy's Avatar
    Join Date
    Aug 2004
    Location
    michigan
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, try sticking some echo statements in it to see how far it's getting.
    ----------------
    bob.kennedy
    ----------------

  10. #10
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?php if (isset($_GET['addjoke'])): // User wants to add a joke
    ?>

    that bit is correct, the wholepage just displays all the jokes in the database, and if you want you can add a joke.

    I don't know where to put echo tags, this is my first ever attempt to learn PHP

  11. #11
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Something smells fishy....?
    this part..
    PHP Code:
    //When clicked, this link will load this page
    //with the joke submission form displayed.
    echo '<p><a href="' $_SERVER['PHP_SELF'] .
    '?addjoke=1">Add a joke!</a></p>'
    is inside the main if statement but I think it should be outside it...
    Try this link idea to see what happens (keep the cod the same a your posted code above)
    http://localhost/path_to_joke/jokes.php?addjoke=1
    (where path_to_jokeis the path to your file)..
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  12. #12
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...that brings up the form to add a new joke, but when u add some text and click submit it goes blank again

    that part of the code you said sounds fishy is exactly as it is in the book

  13. #13
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    could someone let me where i should put the echo statements to check how far it's getting?

    cheers for the help so far

  14. #14
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it's blank then there's an error. If there's an error and you're not seeing it then your error_reporting is too low.
    Put:
    error_reporting(E_ALL);
    at the top if the script (after the <?php tag).

  15. #15
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...didn't seem to do anything

    i checked the error file in the log folder (is that where i should find the errors?) and it didn't show any recent errors regarding that page

  16. #16
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, the script works fine exactly as it is for me. Maybe repost your entire updated file so we can see what's what?

  17. #17
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could it be something to do with it not managing to connect to my MySQL database? Here's the code:

    <body>

    <?php error_reporting(E_ALL);
    if (isset($_GET['addjoke'])): // User wants to add a joke
    ?>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <label>Type your joke herebr />
    <textarea name="joketext" rows="10" cols="40">
    </textarea></label><br />
    <input type="submit" value="SUBMIT" />
    </form>

    <?php else: // Default page display

    //Connect to the database server
    $dbcnx = @mysql_connect('localhost', 'root', 'mypasswd');
    if (!$dbcnx) {
    exit('<p>Unable to connect to the ' .
    'database server at this time.</p>');
    }

    //Select the jokes database
    if (!@mysql_select_db('ijdb')) {
    exit('<p>Unable to locate the joke ' .
    'database at this time.</p>');
    }

    //If a joke has been submitted,
    //add it to the database.
    if (isset($_POST['joketext'])) {
    $joketext = $_POST['joketext'];
    $sql = "INSERT INTO joke SET
    joketext='$joketext',
    jokedate=CURDATE()";
    if (@mysql_query($sql)){
    echo '<p>Your joke has been added.</p>';
    } else {
    echo '<p>Error adding submitted joke: ' .
    mysql_error() . '</p>';
    }
    }

    echo '<p>Here are all the jokes in our database/p>';

    //Request the text of all the jokes
    echo $result = @mysql_query('SELECT joketext FROM joke');
    if (!$result) {
    exit('<p>Error performing query: ' .
    mysql_error() . '</p>');
    }

    //Display the text of each joke in a paragraph
    while ($row = mysql_fetch_array($result)) {
    echo '<p>' . $row['joketext'] . '</p>';
    }

    //When clicked, this link will load this page
    //with the joke submission form displayed.
    echo '<p><a href="' . $_SERVER['PHP_SELF'] .
    '?addjoke=1">Add a joke!</a></p>';

    endif;
    ?>
    </body>

  18. #18
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could it be something to do with it not managing to connect to my MySQL database?
    Then you'd see "Unable to connect to the database server at this time."
    Try this same version with some debug echo's in then
    PHP Code:
    <?php
    error_reporting
    (E_ALL);
    echo 
    'debug 1<br />';
    ?>
    <body>

    <?php
    echo 'debug 2<br />';
    if (isset(
    $_GET['addjoke'])): // User wants to add a joke
    ?>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <label>Type your joke here:<br />
    <textarea name="joketext" rows="10" cols="40">
    </textarea></label><br />
    <input type="submit" value="SUBMIT" />
    </form>

    <?php else: // Default page display
    echo 'debug 3<br />';
    //Connect to the database server
    $dbcnx = @mysql_connect('localhost''root''mypasswd');
    if (!
    $dbcnx) {
    exit(
    '<p>Unable to connect to the ' .
    'database server at this time.</p>');
    }
    echo 
    'debug 4<br />';
    //Select the jokes database
    if (!@mysql_select_db('test')) {
    exit(
    '<p>Unable to locate the joke ' .
    'database at this time.</p>');
    }
    echo 
    'debug 5<br />';
    //If a joke has been submitted,
    //add it to the database.
    if (isset($_POST['joketext'])) {
    $joketext $_POST['joketext'];
    $sql "INSERT INTO joke SET
    joketext='
    $joketext',
    jokedate=CURDATE()"
    ;
    if (@
    mysql_query($sql)){
    echo 
    '<p>Your joke has been added.</p>';
    } else {
    echo 
    '<p>Error adding submitted joke: ' .
    mysql_error() . '</p>';
    }
    }
    echo 
    'debug 6<br />';
    echo 
    '<p>Here are all the jokes in our database:</p>';

    //Request the text of all the jokes
    echo $result = @mysql_query('SELECT joketext FROM joke');
    if (!
    $result) {
    exit(
    '<p>Error performing query: ' .
    mysql_error() . '</p>');
    }

    //Display the text of each joke in a paragraph
    while ($row mysql_fetch_array($result)) {
    echo 
    '<p>' $row['joketext'] . '</p>';
    }

    //When clicked, this link will load this page
    //with the joke submission form displayed.
    echo '<p><a href="' $_SERVER['PHP_SELF'] .
    '?addjoke=1">Add a joke!</a></p>';

    endif;
    ?>
    </body>

  19. #19
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now it says:

    debug 1
    debug 2
    debug 3

  20. #20
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like the connection is failing then.
    Change:
    $dbcnx = @mysql_connect('localhost', 'root', 'mypasswd');
    to:
    $dbcnx = mysql_connect('localhost', 'root', 'mypasswd') or die(mysql_error());

    See if that shows anything.

  21. #21
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now it says:

    debug 1
    debug 2
    debug 3

    Fatal error: Call to undefined function mysql_connect() in c:\program files\apache group\Apache\htdocs\jokes.php on line 30

  22. #22
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aha. The root of the problem. You have no mysql support.
    Edit your php.ini (usually in c:\WINDOWS\php.ini) and add/uncomment the line:
    extension=php_mysql.dll
    then restart apache.

  23. #23
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i un commented that line in the 'php.ini-dist' file (couldn't find just 'php.ini'), was that correct?

    How do you close Apache and start again? (sorry, complete nooby)

  24. #24
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i un commented that line in the 'php.ini-dist' file
    Nope
    If c:\windows\php.ini doesn't exist then copy that php.ini-dist to c:\windows\php.ini
    How do you close Apache and start again?
    Depends how you installed it. If it's installed as a service then from a command prompt you can do 'net stop apache' then 'net start apache'

  25. #25
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my PHP folder is in C: , there's no PHP folder in my WINNT folder. Should i create one and paste the .ini file in there?


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
  •