0
I’m trying to create a script that excludes the image of the database and folder, but the problem is that it is only excluding from the BD and not from the folder.
Tabela equipes
id, nome, foto
Here is the PHP I’m using:
$id = $_GET["id"];
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(isset($_POST["deletar"])){
$sqlDeletar = $pdo->prepare("DELETE FROM equipes WHERE id = :id");
$sqlDeletar->bindValue(":id", $id);
$sqlDeletar->execute();
$dadosDeletar = $sqlDeletar->fetchObject();
unlink("../upload/".$dadosDeletar->foto);
echo "Aqui é o link de redirecionar.";
}else{
if(isset($_POST["nao"])){
echo "Aqui é o link de redirecionar.";
}
}
}
And here’s the form:
<form action="" method="post" enctype="multipart/form-data">
<label>
<input type="submit" name="deletar" value="Excluir">
<input type="submit" name="nao" value="Não excluir">
</label>
</form>
You need to make a select before deleting a record. Because, after it is deleted you no longer have the option "$data->photo"
– Don't Panic