我正在尝试从php oops中删除数据库中的图像。我创建了这个类。它从数据库中删除数据但不像功能不起作用。 Plz帮助我。
<!-- 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');
}
}
}
?>
我尝试了很多代码并尝试了一些不同的方法,但问题仍未解决。
答案 0 :(得分:0)
您正在尝试取消链接名为&#34; $ row [thumbnail_image]&#34;的文件。尝试改变
unlink("fashion/$row[thumbnail_image]");
到
unlink("fashion/" . $row["thumbnail_image"]);