SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP include not redirecting

    Hi, I'm running through the example code in the "PHP and MySQL from Novice to Ninja" book. I have a simple database connection test php file (index.php) that is supposed to call another page (output.html.php) with the include statement but it does not seem to work. I just have a blank page when I go to the url that has both files (those are the only two files in a subdirectory of /var/www/html). Below is the code for both files. Thank you.
    ///index.php

    <?php
    try
    {
    $pdo = new PDO('mysql:host=localhost;dbname=ijdb', 'ijdbuser', 'mypassword');
    $pdo->setAttribute(PDO::ALTER_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $PDO->exec('SET NAMES "utf8");
    }
    catch (PDOException $e)
    {
    $output = 'Unable to connect to the database server.';
    include = 'output.html.php';
    exit();
    }

    $output = 'Database connection established.';
    include 'output.html.php';
    ?>

    //////output.html.php file
    <!DOCTYPE html>
    <html lang="en-us">
    <meta charset="UTF-8" >
    <title>DB Example</title>
    <head>
    </head>

    <body>

    <p>
    <?php echo $output; ?>
    </p>

    </body
    </html>


    I just get blank page. Please help. Thank you.

  2. #2
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    problem fixed. Problem was with this line: $pdo->setAttribute(PDO::ALTER_ERRMODE, PDO::ERRMODE_EXCEPTION);

  3. #3
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    A blank page usually indicates an error.

    To show error messages, you will need to enable them by placing this somewhere in your PHP code:

    Code:
    error_reporting(E_ALL);
    However, when your code is in a live production environment, to ensure to ensure the display of error messages is disabled, use this:
    Code:
    error_reporting(0);
    http://php.net/manual/en/function.error-reporting.php
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain


Tags for this Thread

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
  •