Home » Php » php – MySQL Query displayed in HTML tags problem

php – MySQL Query displayed in HTML tags problem

Posted by: admin February 25, 2020 Leave a comment

Questions:

So I’m working on this little website project, nothing serious, more like fun project
I have this mySQL database to keep posts in it

CREATE TABLE commentsy(
    comment_id int(11) not null AUTO_INCREMENT PRIMARY KEY,
    comment_author varchar(128) not null,
    comment_date datetime not null,
    comment_text TEXT not null,
    comment_photo_id TEXT not null
);

and on my homepage i’d like to dispaly post that goes under id #1

<?php

$conn= mysqli_connect('localhost','root','','wpisy');

if(!$conn){
    die(" error: ".mysqli_connect_error());

}


$sql = "SELECT  `comment_date`, `comment_text`, `comment_photo_id`, 'comment_title' FROM `commentsy` WHERE `comment_id` = 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {

echo"<div class='card'>";
    // output data of each row
    while($row = $result->fetch_assoc()) {
        $title = $row['comment_title'];
        $date = $row['comment_date'];
        $text = $row['comment_text'];
        $pid = $row['comment_photo_id'];




        echo $row['comment_title'];
        echo"<h2>" .$title  ;
        echo"</h2>";
        echo"<div class='Image-Thumbnail'>";
        echo"<img src=./img/$pid height=50% width=50%>";
        echo"</div>";
        echo"<p>";
        echo".$text";
        echo"</p>";
        echo"<div class=toTheRight>" .$date ;
        echo"</div>";




    }
echo"</div>";

    }
else {
    echo "0 results";
}
?>

and the problem is – instead of title being displayed properly it dispalys comment_title on both lines, in h2 tags and line above.

any ideas / suggestions what am i doing wrong here ?
All the other stuff works like a charm.

How to&Answers: