Harinder
Harinder

Reputation: 1257

Php Function to get html tags from database

I Have a old database to maintain .... they have stored html tags in there database and was using old mysql with php to get outupt ... Now i am trying to use it through function and PDO to get output .... not getting output right .... its just giving html tags display insted of formatting the paragraph ... how can i fix it , here is my code --> Function

function movie_page($name,$date){
    global $host, $dbname, $user, $pass;
    $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
    $STH = $DBH->prepare("SELECT * FROM bh_movies WHERE name = ? and re_date = ?");
    $STH->bindValue(1, "$name", PDO::PARAM_STR);
    $STH->bindValue(2, "$date", PDO::PARAM_STR);
    $STH->execute();
    $STH->setFetchMode(PDO::FETCH_ASSOC);
    return $STH;
    }

and output is

$STH = movie_page($id,$date);
     while (($row = $STH->fetch()) !== false) {
    if ($row['actors'] !=''){
    echo '<tr>
            <td><h1><a href="movie_page.php?id='.$row['name'].'">'.$row['name'].'</a></h1></td>
            <td>'.date('d-M-Y',$row['re_date']).'</td>
            <td><a href="movie_page.php?id='.$row['name'].'">
            <img src="'.$row['small_poster'].'" title="'.$row['name'].'" alt="'.$row['name'].'" height="97" width="182"/>
            </a>
            </td>
            <td><a href="movie_page.php?id='.$row['a'].'">
            <td>'.$row['actors'].'</td>
            <td>'.$row['small_desc'].'</td>
            <td>'.$row['big_desc'].'</td>
          </tr>';

     }

i am getting Html tags in output ... instead of format paragraph something like this

<font color="green"><B><u>Characters</u></B></font><br><br> <B>Sonu Dilli (KKC)</B> Emraan Hashmi<BR><BR> Sonu Dilli is a streetsmart 

please help

* INPUT Source *

function insert_data(){
    global $host, $dbname, $user, $pass;
    $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
    $STH = $DBH->prepare("INSERT IGNORE INTO bh_movies 
    (name, bh_link, re_date,  small_poster, big_poster, small_desc, big_desc, actors) 
    value (:name, :bh_link, :re_date, :small_poster, :big_poster, :small_desc, :big_desc, :actors)");
    return $STH;
}

Upvotes: 0

Views: 6901

Answers (2)

TomCat
TomCat

Reputation: 451

html_entity_decode() to decode the HTML from database.

Upvotes: 0

Pekka
Pekka

Reputation: 449395

Your data is being converted into HTML entities at some point. Either find the point where it is being converted (probably using htmlspecialchars()) or decode the data when it comes from the database (using htmlspecialchars_decode()).

Upvotes: 5

Related Questions