简体   繁体   中英

include in php doesnt work

I have two files(b.php and showimages.php) b.php use this :

<?php include('showimages.php'); ?> 

but it doesn't work but when I try to open showimages.php itself it shows the content. whats the problem?

b.php:

<!DOCTYPE html>
<html>
<body>
    <div class="product-row">
        <?php include('showimages.php'); ?>
    </div>
</body>
</html>

showimages.php:

<?php
    $db = mysqli_connect('localhost', 'root', '', 'online_shopping');
    $query = "SELECT * FROM products "  ;   
    $result = mysqli_query($db, $query);
    $row = mysqli_fetch_assoc($result)  ;  
    header("Content-type: image/jpg"); 
    echo $row['pric1'];          
?>

Your HTML has already sent a header Content-Type: text/html so you can't send another one for an image. Instead of include you need to fetch the image via HTML:

<img src="showimages.php" alt="some image">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM