1

i want to store an image in database not by inserting but by updating (by using UPDATE query).

Everything else is updated successfully but its not storing image. I'm using medium blob data type to store image.

Here is my code:

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>

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 :)

2
  • 2
    I do not see the "$_POST["profileimg"];" in your html form. Secondly, you do not access uploaded files using $_POST but by using $_FILES global array Commented Oct 18, 2012 at 18:00
  • 3
    Also, word to the wise, don't store the image in the database, instead process the upload, move the file where you plan to store it on your server and then store the path to the image in the db. Commented Oct 18, 2012 at 18:03

1 Answer 1

1

Two problems:

You do not have an id for the input tag for the file. You need to change <input type="file" name="image" value="" /> to <input type="file" name="image" value="" id = "profileimage" />

Secondly you access files not via $_POST but rather via $_FILES.

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

Comments

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.