1

For some reason it executes the statement and then the binds all values, but not the last value of $postContent.

<?php
    if (isset($_GET['postID']))
    {
        $postID = $_GET['postID'];
        $stmt = $mysqli->prepare("SELECT * FROM Posts WHERE postID = ?");
        $stmt->bind_param('i', $postID);
        $stmt->execute();
        $stmt->bind_result($postID, $postTitle, $postCat, $postUser, $postDateTime, $postContent);
        $stmt->fetch();
        echo $postContent;
        ?>
        <h1><?php echo $postTitle;?></h1>
    </div> <!-- End of box div -->
    <div class="blogroll"> <!-- Start of blogroll div -->
    <div class="top"></div> <!-- Start and end of top div -->

    <div class="post"> <!-- Start of post div -->
        <div class="post_date">Posted by <?php echo $postUser;?> on <?php echo $postDateTime ?> Category : <?php echo $postCat;?></div> <!-- Start and end of post_date div -->
        <div class="post_text"> <!-- Start of post_text div -->
            <?php echo $postContent;?>
        </div> <!-- End of post_text div -->
        <?php
    }
?>
Dharman
  • 30,962
  • 25
  • 85
  • 135
Ste Prescott
  • 1,789
  • 2
  • 22
  • 43

2 Answers2

2

MySQLi is failing to allocate enough memory for the maximum size of a LONGTEXT object (~4Gb).

This is a known bug: https://bugs.php.net/bug.php?id=51386.

The workaround is to convert LONGTEXT columns to MEDIUMTEXT or something else smaller, or consider using an alternative database or interface class.

Ian Mackinnon
  • 13,381
  • 13
  • 51
  • 67
1

This assumes your source table in the database is actually supplying a column for $postContent when you do SELECT *:

View the HTML source that is output by your PHP script, to see if the $postContent is actually appearing in the source but not onscreen. You have not escaped your database output for HTML (encoding < as &lt;, etc...), so it is possible that something in $postContent or an earlier variable is breaking your output. Instead of directly echoing out those variables, wrap each one in htmlspecialchars() when printing them inside HTML.

<?php echo htmlspecialchars($postTitle); ?>
<?php echo htmlspecialchars($postUser); ?>
<?php echo htmlspecialchars($postDateTime); ?>
<?php echo htmlspecialchars($postCat); ?>
<?php echo htmlspecialchars($postContent); ?>
Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
  • The database does supply the column for postContent and it is in the same order as the bind_results show. I have tried what you suggest and no it doesn't show the postContent in the source code of the HTML page. Also the htmlspcialchars() didn't work either but as I plan to have HTML tags eg I will continue to use it. You are being a great help – Ste Prescott Jan 08 '12 at 20:18
  • @user1136076 The only other thing I can suggest is to `var_dump($postContent)` and _all_ of the other variables to be certain they each contain what is expected – Michael Berkowski Jan 10 '12 at 14:40
  • It seems that $postContent isnt getting any value. When I perform the SQL statement in phpMyadmin it does return one record with 6 columns, the last being postContent with type LongText. – Ste Prescott Jan 10 '12 at 17:26
  • I have changed the data type to Text and it now shows on the page. Thanks for your help – Ste Prescott Jan 10 '12 at 17:33
  • @user1136076 That's interesting, I've never encountered that before. – Michael Berkowski Jan 10 '12 at 17:38
  • I wouldn't of thought that would of been a problem but it was the only thing I could think of. – Ste Prescott Jan 10 '12 at 17:49
  • I have asked another question and wonder if you could again shed light as to the fix. Thanks http://stackoverflow.com/questions/8856961/how-to-call-a-php-class-method-from-a-javascript-function – Ste Prescott Jan 13 '12 at 20:43