0
<!DOCTYPE html>

<head>
    <title>Display Picture</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
    <h1>A Picture from Our Collection</h1>
    <?php

    header("Content-type: image/jpeg");

    $id = $_GET["ident"];
    $pat = '/^[0-9]+$/';
    if(!preg_match($pat, $id)){
        exit; // broken image
    }
    $mysqli = new mysqli('localhost','root','9876543210','student13');
    $query = "select image from Picys where ident=$id";

    $result = $mysqli->query($query);

    $err = $mysqli->error;
    if(!empty($err)){
        exit;
    }

    $row = $result->fetch_array(MYSQLI_NUM);
    $bytes = $row[0];

    echo $bytes;
    ?>
    <hr />
    <h2>Tags</h2>
    <?php
    $stmt->close();
    $stmt = $mysqli->prepare("select Tagstr from PicyTags where Picid=?");
    $stmt->bind_param('s',$id);
    $stmt->execute();
    $stmt->bind_result($tag);
    $count = 0;
    while($stmt->fetch()){
        if($count==0){
            echo "<bold>Existing tags:</bold>";
        }
        $count++;
        echo "$tag<br />";
    }
    $mysqli->close();
    ?>
    <br />
    <h3>Add tag</h3>
    <p>You may add tags that characterize the contents of this picture.</p>
    <form action="./AddTag.php?ident=<?php echo $id ?>" method="POST">
        <fieldset>
            <legend>Your tag</legend>
                <input type="text" size="16" maxlength="16" />
        </fieldset>
        <input type="submit" value="Add Tag" />
    </form>
</body>

i cannot display the picture from my database. and where i wrong at? suppose correct ya

and from ADD TAG <h3> there nothing can show out. my output just a

<h1>A Picture from Our collection</h1>

In my browser ! Nothing come out

3
  • You're trying to use a image header on a HTML page, don't think that would work. Try making that php on a separated file and calling it from an image tag ? Commented Jun 8, 2013 at 17:30
  • @Prix. u mean i just delete the header right? and then how should i calling it? i mean in my php function Commented Jun 8, 2013 at 17:40
  • No, I meant you make another file specifically for printing the image with the header you are using and then on the above file u just call something like <img src="my_other_php_file_that_loads_the_image.php?imageId=1"> Commented Jun 8, 2013 at 18:38

1 Answer 1

2

You already send a response with the HTML tags and then you try to change the headers. The headers should be altered before anything is outputted to the browser.

Sign up to request clarification or add additional context in comments.

3 Comments

so how should i change it?
remove header("Content-type: image/jpeg");
after i delete it still display the A Picture from Our Collection. thats all nia

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.