Consider this session:
echo '<img src = "'.$_SESSION['userpic'].'" class = "changepic">';
This is an image which displays the users image in the database with a session variable! However in my site i am changing the users picture with an upload image form, the users picture is getting updated but the old picture stays until i refresh my page... I want to avoid refreshing the page to solve this issue....
<form action = "upload.php" id = "bildUppladdning" method = "post" enctype = "multipart/form-data" target = "hiddenFrame">
<input type = "file" name = "file" id = "fileToUpload" accept="image/*" style = "display:none" onchange="form.submit()">
</form>
Notice that i target an iframe to not be redirected to my action...
if(isset($_FILES['file']) ){
move_uploaded_file($_FILES['file']['tmp_name'],'files/'.$_FILES['file']['name']);
session_start();
$username = $_SESSION['user'];
$userpic = 'files/'.$_FILES['file']['name'];
$id = $_SESSION['id'];
include ("connect.php");
$sql = $con->prepare('UPDATE users SET username=?, userpic=? WHERE id = ?');
$sql->bind_param("ssi",$username,$userpic,$id);
$sql->execute();
$sql->close();
$con->close();
$_SESSION['userpic'] = $userpic;
}
else{
$_SESSION['checked'] = '<div class = "check"> NO</div>';}
And here is my upload form which you probably doesn't need but ill put it here anyways...
For example:
$("#fileToUpload").on('submit', function(response)
{
$.ajax({
url: "update.php"
});
return false;
});
Update.php example
<?php
$_SESSION['userpic'] = $row->userpic;
?>
So to keep it simple I would like to "update" this echo img tag when the form is submitted without refreshing or get redirected..
Any ideas how i could solve this problem?