我在删除代码时遇到错误我已取消链接文件,但数据库中的数据未被删除

时间:2015-09-09 14:03:44

标签: php mysqli

public function deleteuser()
{

    $this->sql = " SELECT admin_img FROM admin_data WHERE admin_id = '$this->admin_id' ";
        $this->res = mysqli_query($this->conxn, $this->sql) 
            or trigger_error($this->err = mysqli_error($this->conxn));
        $this->numRows = mysqli_num_rows($this->res);
        $this->data = mysqli_fetch_assoc($this->res);

        //filename
        $file_name = $this->data['admin_img'];


        $destination="Uploads/".$file_name;


        //delete the file
        if(file_exists($destination)){


                if(unlink($destination)){
            //file removed from the server
            //now remove from the database
                    $this->sql = " DELETE FROM admin_data WHERE admin_id = '$this->admin_id' ";
                    $this->res = mysqli_query($this->conxn, $this->sql)
                    or trigger_error($this->err = mysqli_error($this->conxn));
                    $this->affRows = mysqli_affected_rows($this->conxn);
                    echo $this->affRows;

                    if($this->affRows>0){

                    return TRUE;
                    }
                    else{
                        return FALSE;
                    }



                else{
                     return FALSE;
                }
        }//delete file ends

我已取消链接我上传的文件,但我可以删除我在添加用户文件时存储的数据。 我也没有收到任何错误,但代码总是返回False 我希望代码返回真值。

请帮帮我** **提前致谢

1 个答案:

答案 0 :(得分:0)

在你的取消关联条件

中尝试此操作

取消关联时,您需要提供根路径

if(file_exists($_SERVER['DOCUMENT_ROOT'].$destination)){
  if(unlink($_SERVER['DOCUMENT_ROOT'].$destination)){

  //your delete code
  }
}