0 votes
in Programming by (400 points)

Hi I'm new here and try to explain my problem I'm going to update the profile image into data base when I upload and click on my save button the popup show the message your image upload successfully but when I open my database its can't store on the current user database path I already create the session_start(); but in there I just show my little bit code which is important.

My html code is as following

    <div class="form-group mb-2 pt-2">
                                                                                                                                                                                                                                                 
    <input class='input' type='hidden' name='id' value="<?php echo $id; ?>" />
                                                                                                                                                                                                                                                     
    <input id="avatar" type="file" name="avatar" hidden="" accept="image/png, image/jpeg, image/jpg">
                                                                                                                                                                                                                                                     
    <button id="uploadBtn" type="button" class="btn btn-primary btn-file " ><i class="fa fa-camera" 
    aria-hidden="true"></i> &nbsp Upload Avatar</button>
                                                                                                                                                                                                                                             
   </div>
                                                                                                                                                                                                                                             
   <div class="row">
                                                                                                                                                                                                                                                                 
   <div class="col d-flex justify-content-end pr-5">
                                                                                                                                                                                                                                                                                 
   <button class="btn btn-primary " type="submit" name="profileupload">Save Changes</button>
                                                                                                                                                                                                                                                                 
   </div>
                                                                                                                                                                                                                                             
   </div>

here is my php code

$id = "";
if(isset($_POST['profileupload']))
{
$id = $_POST['id'];
$file=addslashes(file_get_contents($_FILES["avatar"]["tmp_name"]));
$query = "UPDATE users SET avatar = '$file' WHERE id = '$id'";
$query_run = mysqli_query($db,$query);
if($query_run)
{
 echo '<script type = "text/javascript"> alert("image profile upload")</script>';
}
else
{
echo '<script type = "text/javascript"> alert("image profile not upload")</script>';
}
}

Please log in or register to answer this question.

...