SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Blank screen with my php script

    Hi Guys,

    I'm going through 'Build your own database driven web site' by Kevin Yank, 4th edition.

    I'm stuck in chapter 4 page 121

    Ive copied everything, the only difference is Ive used my own web host to create a test site, but thought the only difference would be database name etc....

    At any rate its not throwing up any errors at all, just a blank white screen.

    PHP below.

    PHP Code:
    <?php
    $link 
    mysqli_connect('localhost''web81-johntrain''train567');
    if (!
    $link)
    {
    $output 'Unable to connect to the database server.';
    include 
    'output.html.php';
    exit();
    }

    if (!
    mysqli_set_charset($link'utf8'))
    {
    $output 'unable to set database connection encoding.';
    include 
    'output.html.php';
    exit();
    }

    if (!
    mysqli_select_db($link'web81-johntrain'))
    {
    $output 'Unable to locate the joke databse.';
    include 
    'output.html.php';
    exit()
    }

    $output 'Database connection established.';
    include 
    'output.html.php';
    ?>
    Any help would be great thanks

  2. #2
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,622
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Hi, try throwing some die() statements in there (put it as as the "else" in your if statements)

    The page is just erroring out. It probably isn't connecting to the database. Try using mysql_connect instead of mysqli .
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  3. #3
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks,

    Ive tried mysql instead of mysqli did nothing, I dont mind that its got an error but its just a blank screen... kind of need to know the error before fixing it.

    Is there a problem with the code, im not sure i could go with that since its a sitepoint book (unless ive typed it wrong of course!)

    Also I have no idea what die statements are (Im a beginner!)

  4. #4
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,622
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Hi, your die() statements should be basically like this

    mysql_connect("localhost", "admin", "1admin") or die(mysql_error());

    Haven't tested, but this is what your code should be with them included

    PHP Code:
    <?php 
    $link 
    mysqli_connect('localhost''web81-johntrain''train567') or die(mysql_error()); 
    if (!
    $link

    $output 'Unable to connect to the database server.'
    include 
    'output.html.php'
    exit(); 

    else
    {
    die(
    mysql_error());
    }

    if (!
    mysqli_set_charset($link'utf8')) 

    $output 'unable to set database connection encoding.'
    include 
    'output.html.php'
    exit(); 

    else
    {
    die(
    mysql_error());
    }


    if (!
    mysqli_select_db($link'web81-johntrain')) 

    $output 'Unable to locate the joke databse.'
    include 
    'output.html.php'
    exit() 

    else
    {
    die(
    mysql_error());
    }


    $output 'Database connection established.'
    include 
    'output.html.php'
    ?>
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  5. #5
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Again thanks for looking at this, but alas still blank

  6. #6
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Really stuck on this

  7. #7
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,836
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Try this:

    PHP Code:
    <?php 

    error_reporting
    (-1); 
    ini_set('dispay_errors'TRUE);

    #debug sttuff - saves re-typing 
    defined('jj'); ? NULL define('jj''<br />');
    defined('js'); ? NULL define('jj''&nbsp;&nbsp;');

    echo 
    jj__LINE__jsjs__FILE__; die;


    $link mysqli_connect('localhost''web81-johntrain''train567'); 
    if (!
    $link

    $output 'Unable to connect to the database server.'
    include 
    'output.html.php'
    exit(); 


    if (!
    mysqli_set_charset($link'utf8')) 

    $output 'unable to set database connection encoding.'
    include 
    'output.html.php'
    exit(); 
    }
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  8. #8
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still just a blank screen unfortunately, any more ideas? Could this be a problem with my hosting rather then the script?

    I dont mind that the script isnt work just that its not showing anything at all!

  9. #9
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,836
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Try this and if you still get a blank screen then another page is causing the error:

    PHP Code:

    <?php 
    echo  __FILE__
    die;

    # should display the filename and never ever get here :)



    error_reporting(-1); 
    ini_set('dispay_errors'TRUE);

    #debug sttuff - saves re-typing 
    defined('jj'); ? NULL define('jj''<br />');
    defined('js'); ? NULL define('jj''&nbsp;&nbsp;');
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  10. #10
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, still blank.

    Basically this is a static site with a folder to put this test script in, so not sure what would be clashing with it.

    Could it be a hosting issue?

  11. #11
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,836
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Is there anything working on this new test site you have created?

    Try to get something to work then proceed from there in small steps
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  12. #12
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah Ive thrown up html files on there just fine

  13. #13
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,836
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    OK if the html files are working then:

    1. rename your "whatever-is-working.html" file to "whatever-is-working.php"
    2. include these lines at the top of the "whatever-is-working.php" file:
    3. run "whatever-is-working.php" in your browser

    # "whatever-is-working.php"
    PHP Code:

    <?php 
    echo  __FILE__
    die;
    ?>

    ... Old Html stuff
    Last edited by John_Betong; Mar 16, 2012 at 11:00. Reason: spelling: not my fortey
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  14. #14
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what is contained in output.html.php?

  15. #15
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sometimes your host has error reporting turned off and if there is a syntax error in the page no matter where you put those die/exit statements you just get that nasty blank page. Try putting this at the top of you script after the opening PHP tag:

    Code:
    error_reporting(-1);
    Hopefully that will display the error so you can debug it. Note this is a setting that can be tweaked in the PHP ini if you have that access.

  16. #16
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks everyone for your input, the answer is - I'm a doughnut! Typical beginner I guess....

    I looked through my code again and my last 'exit()' didnt have a ';' at the end, stuck it on, and lo and behold it works!

    So my question is, why didnt that come up as an error? Whats happening to my script if I havent put the ';' at the end?

    Thanks everyone for your help

  17. #17
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Read my last post. PHP was set to not show errors (this can be correct for some servers as you don't want visitors seeing this information!) but for development it doesn't make sense.

    Read up on PHP configuration pertaining to the display of errors - here's a page to get you started:

    http://uk.php.net/manual/en/errorfunc.configuration.php

  18. #18
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    As Leonard said, your error reporting is turned off. It's very important to turn on your error reporting (or view the error log on your server if you have access) when developing. It'll make these simple problems become quick and easy. It is very painful to try and develop anything without the ability to access errors. =p


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
  •