hi,
i am new to php. I am trying to fetch the image stored in database by using mysqli but couldnt fetch it. Please help me with this. Please find the code and let me know where i am lacking...

<?php 
$link = mysqli_connect('localhost','root','','db_image') or die(mysqli_connect_error());

if(isset($_POST['btn_submit'])){
extract($_POST);

$file_name=$_FILES["image"]["name"];
$file_tmp=$_FILES["image"]["tmp_name"];

$check = getimagesize($_FILES["image"]["tmp_name"]);
print_r($check);

echo'<br>';
if($check !== false){
    $file_name = $_FILES["image"]["name"];
    print_r($file_name);
    echo "<br>";
    $imgContent = addslashes(file_get_contents($file_tmp));
    $query = "insert into insert_image(Image,Image_Name,user_regon) values('$imgContent','$file_name', NOW())";
    if(mysqli_query($link,$query)){
        echo"Image uploaded successfully";  
    }
    else{
        echo"Failed to upload image". mysqli_error($link);; 
    }   
}else{
        echo "Please select an image file to upload.";
    }   
}

if(isset($_POST['btn_display'])){ 
 $query = "select * from insert_image"; 
 $result = mysqli_query($link,$query);
 while($row = mysqli_fetch_assoc($result)){
    extract($row);
    //$imgdata = $row["Image"];
    echo $row[0] . ': ' . $row[1] . ' ' . $row[2];
    //print_r($imgdata);
?>
<table border="1">
<tr>
    <td>ID</td>
    <td><?=$id?></td>
</tr>
<tr>
    <td>Image</td>
    <td><?=$Image?></td>
</tr>    
</table>
<?php   
    echo "User ID". $id;
    echo "<br />";
}
mysqli_close($link);
}

?>
<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
        Select image to upload:
        <input type="file" name="image"/>
        <input type="submit" name="btn_submit" value="UPLOAD"/>
        <input type="submit" name="btn_display" value="Display"/>
</form>
</body>
</html>

Your method are wrong for BLOBs - read this manual

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.