简体   繁体   English

If-Else语句错误

[英]If-Else Statement Error

The program should be like this : 该程序应如下所示:

  • The code will check if there's any file available for uploading. 该代码将检查是否有任何文件可上传。
  • If there's any file found. 是否找到任何文件。 It will upload and the texts will save in the database. 它将上传并且文本将保存在数据库中。
  • But if there's no file found, it will not upload and the path will not also save but the texts will still save in the database. 但是,如果找不到文件,则不会上传文件,路径也不会保存,但文本仍会保存在数据库中。

What really happens: 实际发生的情况:

  • The texts are saving 文本正在保存
  • The image path is still saving! 图像路径仍在保存! So it'll be a problem for retrieving the image on the later part. 因此,在后面的部分中检索图像将是一个问题。

As you noticed: 如您所见:

  • I removed the 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_pathif那是我认为不保存图像路径但仍在保存的方式。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM