Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My PHP tag is not working, the code editor is not registering it

i have a php tag that is for some reason not working, when i first wrote the code it worked but after a while of me doing different things with the code it suddenly stopped working.

underneath here is my code

<?php 
// Include the database configuration file  
require_once 'config.php'; 
 
// Get image data from database 
$result = $db->query("SELECT billede FROM billeder ORDER BY ret_id DESC"); 
?>

<?php if($result->num_rows > 0){ ?> 
    <div class="gallery"> 
        <?php while($row = $result->fetch_assoc()){ ?> 
            <img src="data:image/jpg;charset=utf8;base64,<?php echo base64_encode($row['image']); ?>" /> 
        <?php } ?> 
    </div> 
<?php }else{ ?> 
    <p class="status error">Image(s) not found...</p> 
<?php } ?>

the problem is with this line. the question mark in the closing tag does not get registered as php.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<img src="data:image/jpg;charset=utf8;base64,<?php echo base64_encode($row['image']); ?>" /> 

I tried to go back but even then it still dit not work. its as if VS Code doesnt register it. does anyone know how to fix?

this is a picture of how it looks in my code editor VS Code

>Solution :

One solution would be to echo the image tag, and then change it. So you have this line:

echo '<img src="data:image/jpg;charset=utf8;base64,'.base64_encode($row['image']).'" />';

So in your code it would be:

<?php 
// Include the database configuration file  
require_once 'config.php'; 
 
// Get image data from database 
$result = $db->query("SELECT billede FROM billeder ORDER BY ret_id DESC"); 
?>

<?php if($result->num_rows > 0){ ?> 
    <div class="gallery"> 
        <?php 
        while ($row = $result->fetch_assoc()){ 
            echo '<img src="data:image/jpg;charset=utf8;base64,'.base64_encode($row['image']).'" />';
        } 
        ?> 
    </div> 
<?php }else{ ?> 
    <p class="status error">Image(s) not found...</p> 
<?php } ?>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading