jemtan990
jemtan990

Reputation: 453

How do I display information using MYSQLi and PHP?

I am using MYSQLi (from this website: http://codular.com/php-mysqli) and getting a blank page.

<html>
<body>  
    <h1>TEST21</h1>

    <?php

    error_reporting(E_ALL);  ini_set('display_errors', 1);

    $db = new mysqli('localhost', 'Brendan', 'password', 'Library');

    if($db->connect_errno > 0){
        die('Unable to connect to database [' . $db->connect_error . ']');
    }

    echo "STEP1";

    //STEP 2

    $sql = <<<SQL
        SELECT *
        FROM 'BOOK'
        WHERE 'ISBN10' > 0
    SQL;

    if(!$result = $db->query($sql)){
        die('There was an error running the query [' . $db->error . ']');
    }

    echo "STEP2";

    ?>

</body>

Upvotes: 1

Views: 137

Answers (1)

Phil
Phil

Reputation: 164730

The whacky thing with HEREDOC is that the closing identifier must not have any leading spaces (must not be indented). See the big warning here - http://php.net/manual/language.types.string.php#language.types.string.syntax.heredoc

You're also using the wrong quote characters in your query. I'd simplify it all down to this...

$sql = 'SELECT * FROM `BOOK` WHERE `ISBN10` > 0';

Upvotes: 4

Related Questions