dounai9294 2015-03-15 18:48
浏览 27

删除和不同于PHP oops中的图像

I'm trying to delete image from database in php oops. I created this class. It delete data from data base but not unlike function is not working some one. Plz help me.

<!-- session start --> 
 <?php 
if (($session->logged_in) && ($session->isAdmin())) {


}
 else{
header("Location: index.php");

}
?>
<!-- session end here -->

 <?php

 $obj=new Crud("localhost","root","","3g");
 class Crud{
    public $mysqli;

public $data;

public function __construct($host,$username,$password,$db_name){

    $this->mysqli = new mysqli($host, $username, $password, $db_name);

    if(mysqli_connect_errno()) {

        echo "Error: Could not connect to database.";

    exit;

    }
    /*else{
        echo"Your Database successfully connected"; 
    }*/

}

public function __destruct(){
    $this->mysqli->close(); 
}





 public function read(){

    $query="SELECT * FROM fashion";

    $result= $this->mysqli->query($query);

    $num_result=$result->num_rows;


    if($num_result>0){
        while($rows=$result->fetch_assoc()){

            $this->data[]=$rows;

            //print_r($rows);


        }

        return $this->data;
    }

 }


 public function delete($id){

 $sql=mysql_query("select * from fashion where where id='$id'");
$row=mysql_fetch_array($sql);

unlink("fashion/$row[thumbnail_image]");


    $query="DELETE FROM fashion WHERE id='$id'";

    $result= $this->mysqli->query($query) or die(mysqli_connect_errno()."Data cannot inserted");

    if($result){
        header('location:fashion.php'); 
    }


}




 }

 ?>

I have tried soo many codes and try some different ways but the problem is still not solved.

  • 写回答

1条回答 默认 最新

  • dpojoxa5613 2015-03-15 19:00
    关注

    you are trying to unlink a file named "$row[thumbnail_image]" try changing

    unlink("fashion/$row[thumbnail_image]");
    

    to

    unlink("fashion/" . $row["thumbnail_image"]);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型