[英]If-Else Statement Error
The program should be like this : 该程序应如下所示:
What really happens: 实际发生的情况:
As you noticed: 如您所见:
avatar_image_path
on if
that's how I thought for the image path not to be saved but it is still saving. 我删除了avatar_image_path
, if
那是我认为不保存图像路径但仍在保存的方式。 Code: 码:
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!";
}
first of all you have to save old profile image in hidden field. 首先,您必须将旧的个人资料图片保存在隐藏字段中。
<html>
<input type="hidden" name="old_image" value=<?php echo $row['image'];?>/>
<input type="file" name="new_image"/>
</html>
now when you submit a form then check 现在,当您提交表格时,然后检查
<?php
if($_FILES['new_image']['name']!="" && $_POST['old_image']=="")
{
echo "upload process...";
}
else
{
echo "save old image in database.";
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.