0

I have saved some HTML data in mysql using php 64base_encode function

$title = $_POST['title'];
$content = base64_encode($_POST['content']);
$sqlTestimonail = "INSERT INTO staticpages (title, content) VALUES ('" . $title . "', '" . $content . "')";

//above code is stroing values in mysql

but when i fetch this and want to show this as HTML it will print it like string instead of rendering it as HTML I am using 64base_decode function to show below is my code

   <main class="ps-main">
        <div class="ps-banner">
            <?php include('includes/slider.php'); ?>
        </div>

    </div>
    <!----here we cut banner html and show this in static page -->
    <?php
    $printContent = "banner";
    $sql_static_banner = "select * from staticpages where title='" . $printContent . "'";
    $query_static_banner = mysqli_query($con, $sql_static_banner);
    if (mysqli_num_rows($query_static_banner) > 0) {
        $print_static_banner = mysqli_fetch_array($query_static_banner);
        echo base64_decode($print_static_banner['content']);
    }
    ?>
    <div class="ps-section--features-product ps-section masonry-root pt-40 pb-80"></div>

if i view page source than echoed variable data show like this

<div>&nbsp;&lt;div class="ps-section masonry-root pt-80 pb-40"&gt;</div><div>
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

1 Answers1

-1

You didnt show the code to store the data in the database. Maybe before it is stored it goes through htmlspecialchars? Anyway if you base64 encode/decode it should not be needed.

To address this issue you can use https://www.php.net/manual/en/function.htmlspecialchars-decode.php to convert special entities to characters.

echo htmlspecialchars_decode('&nbsp;&lt;div class="ps-section masonry-root pt-80 pb-40"&gt;');
&nbsp;<div class="ps-section masonry-root pt-80 pb-40">

So in your case echo base64_decode($print_static_banner['content']); becomes echo htmlspecialchars_decode(base64_decode($print_static_banner['content']));

blahy
  • 1,294
  • 1
  • 8
  • 9