hi got simple delete script, can delete 1 file in folder. tried different stuff trying loop unlink wont work. knows how done?
$id = $_get['id']; $sql_get = "select shop.id, shop.overskrift, shop.pris, shop.text, shop_pictures.shoppictures_id, shop_pictures.shop_pictures_file shop inner join shop_pictures on shop.id = shop_pictures.fk_shop_pictures_shop_id id=$id"; $result_get = mysqli_query($connection, $sql_get); $row = mysqli_fetch_all($result_get); $sql = "delete shop id=$id"; $result = mysqli_query($connection, $sql); $sql = "delete shop_pictures fk_shop_pictures_shop_id=$id"; if(!empty($row)) { foreach($row $data) { unlink('../../img/shop_pictures/'.$data['shop_pictures_file']); } } $result = mysqli_query($connection, $sql); //header('location: ../members.php');exit;
your code incredibly susceptible sql injection may want address that. however, need loop through results.
$row = mysqli_fetch_array($result_get);
fetches 1 result, make sure use instead:
$row = mysqli_fetch_all($result_get, mysqli_assoc);
if(!empty($row) { foreach($row $data) { unlink('../../img/shop_pictures/'.$data['shop_pictures_file']); } }
alternatively this:
while ($row = mysql_fetch_array($result_get)) { unlink('../../img/shop_pictures/'.$row['shop_pictures_file']); }
that should point in right direction.
Comments
Post a Comment