upload and display image php mysqli
<p>i need help with my display image, the display is correct but i dont know why the image doesnt appear. </p>

<pre class="lang-html prettyprint-override"><code>CREATE TABLE `images` (
  `id` int(11) NOT NULL,
  `name` varchar(100) DEFAULT NULL,
  `size` int(11) DEFAULT NULL,
  `type` varchar(20) DEFAULT NULL,
  `content` mediumblob
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
</code></pre>



<p>and this is my "<strong>upload.php</strong>"</p>

<pre class="lang-html prettyprint-override"><code>&lt;?php

// Check for post data.
if ($_POST &amp;&amp; !empty($_FILES)) {
    $formOk = true;

    //Assign Variables
    $path = $_FILES['image']['tmp_name'];
    $name = $_FILES['image']['name'];
    $size = $_FILES['image']['size'];
    $type = $_FILES['image']['type'];

    if ($_FILES['image']['error'] || !is_uploaded_file($path)) {
        $formOk = false;
        echo "Error: Error in uploading file. Please try again.";
    }

    //check file extension
    if ($formOk &amp;&amp; !in_array($type, array('image/png', 'image/x-png', 'image/jpeg', 'image/pjpeg', 'image/gif'))) {
        $formOk = false;
        echo "Error: Unsupported file extension. Supported extensions are JPG / PNG.";
    }
    // check for file size.
    if ($formOk &amp;&amp; filesize($path) &gt; 500000) {
        $formOk = false;
        echo "Error: File size must be less than 500 KB.";
    }

    if ($formOk) {
        // read file contents
        $content = file_get_contents($path);

        //connect to mysql database
        if ($conn = mysqli_connect('localhost', 'root', '', 'upload')) {
            $content = mysqli_real_escape_string($conn, $content);
            $sql = "insert into images (name, size, type, content) values ('{$name}', '{$size}', '{$type}', '{$content}')";

            if (mysqli_query($conn, $sql)) {
                $uploadOk = true;
                $imageId = mysqli_insert_id($conn);
            } else {
                echo "Error: Could not save the data to mysql database. Please try again.";
            }

            mysqli_close($conn);
        } else {
            echo "Error: Could not connect to mysql database. Please try again.";
        }
    }
}
?&gt;

&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Upload image to mysql database.&lt;/title&gt;
        &lt;style type="text/css"&gt;
            img{
                margin: .2em;
                border: 1px solid #555;
                padding: .2em;
                vertical-align: top;
            }
        &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;?php if (!empty($uploadOk)): ?&gt;
            &lt;div&gt;
                &lt;h3&gt;Image Uploaded:&lt;/h3&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;img src="image.php?id=&lt;?=$imageId ?&gt;" width="150px"&gt;
                &lt;strong&gt;Embed&lt;/strong&gt;: &lt;input size="25" value='&lt;img src="image.php?id=&lt;?=$imageId ?&gt;"&gt;'&gt;
            &lt;/div&gt;

            &lt;hr&gt;
        &lt;?php endif; ?&gt;

        &lt;form action="&lt;?=$_SERVER['PHP_SELF']?&gt;" method="post" enctype="multipart/form-data" &gt;
          &lt;div&gt;
            &lt;h3&gt;Image Upload:&lt;/h3&gt;
          &lt;/div&gt;
          &lt;div&gt;
            &lt;label&gt;Image&lt;/label&gt;
            &lt;input type="hidden" name="MAX_FILE_SIZE" value="500000"&gt;
            &lt;input type="file" name="image" /&gt;
            &lt;input name="submit" type="submit" value="Upload"&gt;
          &lt;/div&gt;
        &lt;/form&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>



<p>then this is my "<strong>image.php</strong>" </p>

<pre class="lang-html prettyprint-override"><code>&lt;?php

    // verify request id.
    if (empty($_GET['id']) || !is_numeric($_GET['id'])) {
        echo 'A valid image file id is required to display the image file.';
        exit;
    }

    $imageId = $_GET['id'];

    //connect to mysql database
    if ($conn = mysqli_connect('localhost', 'root', '', 'upload')) {
        $content = mysqli_real_escape_string($conn, $content);
        $sql = "SELECT type, content FROM images where id = {$imageId}";

        if ($rs = mysqli_query($conn, $sql)) {
            $imageData = mysqli_fetch_array($rs, MYSQLI_ASSOC);
            mysqli_free_result($rs);
        } else {
            echo "Error: Could not get data from mysql database. Please try again.";
        }
        //close mysqli connection
        mysqli_close($conn);

    } else {
        echo "Error: Could not connect to mysql database. Please try again.";
    }   

    if (!empty($imageData)) {
        // show the image.
        header("Content-type: {$imageData['type']}");
        echo $imageData['content'];
    }
?&gt;
</code></pre>



<p>every time I try to upload an image process was successful but the picture I uploaded it does not appear. but that appears only image error. please anyone who can help me?</p>

<p>or is there any of you can give me a tutorial how to upload and display images using the database?</p>