hope everyone is fine there, i just wanted to ask that i want to display the image im storing in the database using php.. but i dont know how to display it, would i be able to retrieve it simply by echoing?? im not getting how would the whole process will go..please help..heres my code

thnx for ur time :))

 <form id="form" method="post" action="update-profile-action.php" enctype="multipart/form-data">
        <label for="Fname">First Name:</label> <input type="text" id="Fname" class="text" value="<?php echo $firstname; ?>" name="Fname" /> <br /><br />
        <label for="Lname">Last Name:</label> <input type="text" id="Lname" class="text" value="<?php echo $lastname; ?>" name="Lname" /><br /> <br />

<?php 
if ($_SESSION["type"]=="T")
{
?>        
        <label>Profile Image:</label> <input type="file" name="profileimg" value="" /><br /><br />
        <label>Qualification:</label><br />
        <textarea name="qualification" class="text" id="qualification"><?php echo $qualification;?></textarea><br /><br />
        <label>Education & Teaching History:</label><br />
        <textarea name="briefintro" class="text" id="intro"><?php echo $briefintro; ?></textarea><br /><br />
<?php
}
?>
        <input type="submit" class="mybutton" value="Update Profile" />

    </form>

and this is update-profile-action.php

<?php include("../includes/config.php");?>
<?php
$Fname=$_POST["Fname"];
$Lname=$_POST["Lname"];
$image=$_FILES["profileimg"];
$briefintro=$_POST["briefintro"];
$qualification=$_POST["qualification"];

$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }


 mysql_select_db($dbname, $con);
$query=("UPDATE accounts SET firstname='".$Fname."' , lastname='".$Lname."' ,  profileimg='".$image."' ,  briefintro='".$briefintro."',  qualification='".$qualification."' WHERE id=".$_SESSION['id']);
$result = mysql_query($query);
header("Location: update-profile.php?status=3");
mysql_close($con);
?>

Dani AI

Generated

Short diagnosis: the value in $_FILES is an array, not something you can echo directly, and assigning that array into your SQL (as in the original update script) will not store the binary image. is correct that an <img> tag will display an image — but the src must be a valid URL or a script that returns image bytes. is also right: moving the uploaded file to a permanent location is the simplest and most common solution.

Recommended approaches (choose one)

  • Filesystem (recommended for most sites): move the uploaded file from $_FILES['profileimg']['tmp_name'] into an uploads/ folder, save the filename and MIME type to the database, then use a normal <img src="uploads/filename.jpg">. Advantages: simpler, faster, easier to serve with caching and CDNs.

  • Database BLOB (if you must): read the tmp file contents and store the bytes and MIME type in a BLOB column using a prepared statement. To serve, create a small script (e.g., showimage.php?id=...) that sets Content-Type: to the stored MIME type and echoes the binary data. Important: send no output before headers, and use PDO or mysqli with parameter binding (avoid deprecated mysql_*).

Example retrieval (very short, conceptual):

$stmt = $pdo->prepare("SELECT mime, data FROM accounts WHERE id=?");
$stmt->execute([$id]);
$row = $stmt->fetch();
header("Content-Type: ".$row['mime']);
echo $row['data'];

Quick troubleshooting checklist

  • Confirm your form uses enctype="multipart/form-data".
  • Check $_FILES['profileimg']['error'] and tmp_name with var_dump() while debugging.
  • Verify post_max_size / upload_max_filesize and folder permissions for uploads/.
  • Use prepared statements; validate file type and size; store MIME type or extension so your output script knows what Content-Type to send.

This should make it clear why echoing the raw $_FILES value fails and which practical fixes will work.

Recommended Answers

All 5 Replies

You can just echo it, echo "<img src=". $image ." />";

thanx for ur response :)
i've echoed it by the same method but its not showing the image...nor giving any type of error.. please help

You first need to move the image to a permanent location. See this thread.

@pirates is it necessary to move image to a folder??? im storing the image in the database using medium blob type...i cant understand, need help

Okay, see this page in the manual about what part of $_FILES to use in your query.

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.