程序应该是这样的:
真正发生的事情:
你注意到了:
avatar_image_path
上的if
,这就是我想到的图像路径不能保存但它仍在保存。代码:
if ($_FILES["file"]["name"] == 0)
{
$updateQuery = "UPDATE `users`.`info` SET `password` = '$newPass',`contact_number` = '$newConNum',`user_address` = '$newAdd',`email_address` = '$newEmail', WHERE `info`.`username` = '$username' AND `info`.`password` = '$userpass' AND `info`.`firstname` = '$firstName' AND `info`.`lastname` = '$lastName' AND `info`.`admin_level` =$adminLvl AND `info`.`contact_number` = '$ConNum' AND `info`.`user_address` = '$usrAdd' AND `info`.`avatar_image_path` = '$avaImgPth' ";
$executeQuery=$con->query($updateQuery);
echo "Profile successfully UPDATED!";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"], "avatar/owner-".$_SESSION['username']."-fname-".$_SESSION['fname']."-l_name-".$_SESSION['lname']."-filename-".$_FILES["file"]["name"]);
$updateQuery1 = "UPDATE `users`.`info` SET `password` = '$newPass',`contact_number` = '$newConNum',`user_address` = '$newAdd',`email_address` = '$newEmail',`avatar_image_path` = '$filepath' WHERE `info`.`username` = '$username' AND `info`.`password` = '$userpass' AND `info`.`firstname` = '$firstName' AND `info`.`lastname` = '$lastName' AND `info`.`admin_level` =$adminLvl AND `info`.`contact_number` = '$ConNum' AND `info`.`user_address` = '$usrAdd' AND `info`.`avatar_image_path` = '$avaImgPth' ";
$executeQuery1=$con->query($updateQuery1);
echo "Profile successfully UPDATED!";
}
答案 0 :(得分:0)
首先,您必须在隐藏字段中保存旧的个人资料图片。
<html>
<input type="hidden" name="old_image" value=<?php echo $row['image'];?>/>
<input type="file" name="new_image"/>
</html>
现在当您提交表格时,请检查
<?php
if($_FILES['new_image']['name']!="" && $_POST['old_image']=="")
{
echo "upload process...";
}
else
{
echo "save old image in database.";
}
?>