hi everyone, i want to store an image in database not by inserting but by updating (by using UPDATE query)
and hers my code... everything else is updated successfully but its not storing image..please help me to solve the problem..
im using medium blob data type to store image

this is my update-profile.php

    <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="image" value="" /><br /> <br />
        <label>Qualification:</label><textarea name="qualification" class="text" id="qualification"><?php echo $qualification;?></textarea><br /><br />
        <label>Education & Teaching History:</label> <textarea name="briefintro" class="text" id="intro"><?php echo $briefintro; ?></textarea><br /><br />
<?php
}
?>
        <input type="submit" class="mybutton" value="Update Profile" />

    </form>

this is my update-profile-action.php

<?php include("../includes/config.php");?>
<?php
$Fname=$_POST["Fname"];
$Lname=$_POST["Lname"];
$image=$_POST["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);
?>

i copied only the related data from update-profile.php to making it more easy to read :)
any kind of help will be appreciated :)

Recommended Answers

All 3 Replies

Well for starters in update-profile-action.php you refer to $_POST["profileimg"], but the field in update-profile.php has name="image"
Next, you don't access the image file with $_POST, you use $_FILES and associated indexes/functions. And you don't actually store the image in the database, you just store the path (or just the filename) in the DB. Then your code elsewhere uses this file name to access the file.

Do a quick Google search on file upload / image upload forms in PHP, should give you some decent tutorials.

-EF

Member Avatar for LastMitch

@Riu 2009

I don't think it's best to store the image in the database. Plus you can search this topic in Daniweb.

Where is your profileimg = '$image' from your input:

<label>Profile Image:</label> <input type="file" name="image" value="" /><br /> <br />

Instead of this:

$query=("UPDATE accounts SET firstname='".$Fname."' , lastname='".$Lname."' , profileimg='".$image."' , briefintro='".$briefintro."', qualification='".$qualification."' WHERE id=".$_SESSION['id']);

Try this:

$query = ("UPDATE accounts SET firstname = '$Fname', lastname = '$Lname', profileimg = '$image', briefintro = '$briefintro', qualification = '$qualification', WHERE id = '$id'");
commented: To Rectify what some retard did to LastMitch +0

**Hello guys my problem is that, when i edit my form and dont want to modify my image but when i submit the image is disapeer ...please help
**

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.