mohsin_sharif57 mohsin_sharif57 - 3 months ago 14
SQL Question

my JavaScript script is not gonna echo in php

i have a ads script which i stored in my database using textarea field. but when i echo that script in php. then it will not working.
this is my script which i saved in database by using textarea field.

<script type="text/javascript">
( function() {
if (window.CHITIKA === undefined) { window.CHITIKA = { 'units' : [] }; };
var unit = {"calltype":"async[2]","publisher":"seeknfameads","width":300,"height":250,"sid":"Chitika Default","color_site_link":"337ab7","color_text":"337ab7"};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write('<div id="chitikaAdBlock-' + placement_id + '"></div>');
}());
</script>
<script type="text/javascript" src="//cdn.chitika.net/getads.js" async></script>


And when i fetch field and try to echo this. it is not working.

$sql4 = "SELECT * FROM abc ORDER BY id DESC LIMIT 1";
$query4 = $conn->query($sql4);
$row4 = $query4->fetch(PDO::FETCH_ASSOC);
$video_des=$row4['video_des'];
$rowc = $query4->rowCount(PDO::FETCH_ASSOC);
if ($rowc>=1){
<script><?php echo $video_des;?></script>
}


please help to fix this problem.

Answer

As you are already inserting value of video_des with <script> and </script> tag

You don't need to add <script> tag again, Please try below.

 $sql4 = "SELECT * FROM abc ORDER BY id DESC LIMIT 1";
        $query4 = $conn->query($sql4);
        $row4 = $query4->fetch(PDO::FETCH_ASSOC);
        $video_des=$row4['video_des'];
        $rowc = $query4->rowCount(PDO::FETCH_ASSOC);
        if ($rowc>=1){
          echo $video_des;
        }
Comments