Displaying unnecessary HTML when showing content from MySQL database.

Posted by ThatMacLad on Stack Overflow See other posts from Stack Overflow or by ThatMacLad
Published on 2010-06-12T15:46:39Z Indexed on 2010/06/12 15:52 UTC
Read the original article Hit count: 221

Filed under:
|

My homepage pulls in content from my MySQL database to create a blog. I've got it so that it only displays an extract from the posts. For some reason it displays HTML tags as well rather than formatting it using the tags (See picture below). Any help is appreciated.

Homepage:

<html>
    <head>
        <title>Ultan Casey | Homepage</title>
        <link rel="stylesheet" href="css/style.css" type="text/css" />
    </head>
    <body>
         <div class="wrapper">
             <div id="upperbar">
             <a href="#">Home</a>
             <a href="#">About Me</a>
             <a href="#">Contact Me</a>
             <a href="http://www.twitter.com/UltanKC">Twitter</a>
         <form id="search-form" action="/search" method="get">
             <input type="text" id="textarea" size="33" name="q" value=""/>
             <input type="submit" id="submit" value="Search"/>
         </form>
             </div>
             <div id="banner">
             <img src="images/banner.jpg">
             </div>
             <div class="sidebar"></div>
             <div class="posts">
             <?php
             mysql_connect ('localhost', 'root', 'root') ;
             mysql_select_db ('tmlblog');

             $sql = "SELECT * FROM php_blog ORDER BY timestamp DESC LIMIT 5";

             $result = mysql_query($sql) or print ("Can't select entries from table php_blog.<br />" . $sql . "<br />" . mysql_error());

             while($row = mysql_fetch_array($result)) {

                 $date = date("l F d Y", $row['timestamp']);

                 $title = stripslashes($row['title']);
                 $entry = stripslashes($row['entry']);
                 $id = $row['id'];

                 ?>
                  <?php echo "<p id='title'><strong><a href=\"post.php?id=". $id . "\">" . $title . "</a></strong></p>"; ?><br />

                        <div class="post-thumb"><img src="thumbs/<?php echo $id ?>.png"></div>
                        <?php echo htmlspecialchars(substr($entry, 0, 1050)) ?>...   
                        <br>          

                        <hr><br />
                        Posted on <?php echo $date; ?>
                        </p>
                        </div>

                                    </div>


                            </p 


                            <?php
                        }
                        ?>
                       </div> 
             </div>

         </div>
    </body>
</html>

Image: alt text

© Stack Overflow or respective owner

Related posts about mysql

Related posts about html