Okey所以当用户更改他们的个人资料图片时我遇到了问题。如果我愚蠢的头脑理解正确(我认为)这是由于我的会话没有更新...所以这是我的上传文件,用户可以将图像文件上传到数据库,图像插入和它工作正常但即使在数据库中更改了图像我仍然会在插入时看到旧图像...只有当我注销并登录才能看到新图片时,
不知道是否有帮助,但这是我的代码
<?php
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();
echo '<div id = "check"> Your image was succesfully uploaded</div>';
}
else{
echo "no files";}
?>
这是我的登录信息,如果这样也更容易:
<?php
include('connect.php');
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM users";
$result = $con->query($query);
while($row = $result->fetch_object())
{
if($username == $row->username)
{
$checkPassword = password_verify($password,$row->password);
if($checkPassword ){ // betyder om det är sant
session_start();
$_SESSION['loggedIn'] = true;
$_SESSION['user'] = $row->username;
$_SESSION['admin'] = $row->admin;
$_SESSION['userpic'] = $row->userpic;
$_SESSION['id'] = $row->id;
header("Location:music.php?success");
exit();
$fail = false;
}
}
else{
$fail = true;
if($fail){
echo "<script>
alert('You typed in wrong password or username, please try again mate!');
window.location.href='music.php';
</script>";
}
}
}?>
任何帮助超过赞赏,但请尽量保持简单愚蠢
答案 0 :(得分:1)
您没有在会话中更新它!。
您的会话在当前登录时填充,您需要更新
您的上传脚本中的$_SESSION['userpic'] = $userpic;
答案 1 :(得分:1)
当用户修改图像时,可以通过这些步骤来实现