Jump to content

[SOLVED] Php Delete


dropfaith

Recommended Posts

I have no idea why this doesnt work i know how to delete from database but im trying to integrate so i can delete from the server as well

 

 

<?php
// includes
include("../template/conf.php");
$Id = mysql_escape_string($_GET['Id']);	
$result = mysql_query("SELECT * FROM gallery WHERE Id='$Id'") 
or die(mysql_error()); 

  
      $destination = 'home/www/dropfaithproductions.com/www/test/images/';
      $uploaded = $row['uploaded']; //assume that this is the image_name field from your database
      //unlink function return bool so you can use it as conditon
      if(unlink($img_dir.$image_name) && unlink($img_thmb.$image_name)){
          //assume that variable $image_id is queried from the database where your image record your about to delete is...
          

$sql = "DELETE FROM gallery WHERE Id='$Id'";
          $qry = mysql_query($sql);
      }else{
           echo 'ERROR: unable to delete image file!';
      }



?>

Link to comment
https://forums.phpfreaks.com/topic/123502-solved-php-delete/
Share on other sites

okay i can get it removing the file from mysql using this

 

<?php
// includes
include("../template/conf.php");
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
mysql_select_db($db) or die ("Unable to select database!"); 
// connects to db above
$Id = mysql_escape_string($_GET['Id']);	
$result = mysql_query("SELECT * FROM gallery WHERE Id='$Id'") 
or die(mysql_error()); 
$sql = "DELETE FROM gallery WHERE Id='$Id'";
      $destination = 'home/www/dropfaithproductions.com/www/test/images/';
      $uploaded = $row['uploaded']; //assume that this is the image_name field from your database
      //unlink function return bool so you can use it as conditon
      if(unlink($destination.$uploaded)){
          //assume that variable $Id is queried from the database where your image record your about to delete is...
      }
?>

but get this error for the delete from server

Notice: Undefined variable: row in /home/www/dropfaithproductions.com/www/test/admin/deleteimages.php on line 16

 

Warning: unlink(home/www/dropfaithproductions.com/www/test/images/) [function.unlink]: No such file or directory in /home/www/dropfaithproductions.com/www/test/admin/deleteimages.php on line 18

Link to comment
https://forums.phpfreaks.com/topic/123502-solved-php-delete/#findComment-638125
Share on other sites

okay so i can get it deleteing images now if i direct link the image

      $uploaded = 'IMAGE NAME'; //assume that this is the image_name field from your database

 

but to make that work dynamic  i cant get it to define that row also it fails to remove from mysql  properly

Link to comment
https://forums.phpfreaks.com/topic/123502-solved-php-delete/#findComment-638132
Share on other sites

<?php header('Location: deleteimage.php');?>

<?php

// includes

include("../template/conf.php");

$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

mysql_select_db($db) or die ("Unable to select database!");

// connects to db above

$Id = mysql_escape_string($_GET['Id']);

$result = mysql_query("SELECT * FROM gallery WHERE Id='$Id'")

or die(mysql_error());

$row = mysql_fetch_object($result);

 

      $destination = '/home/www/dropfaithproductions.com/www/test/images/';

      $uploaded = $row->uploaded; //assume that this is the image_name field from your database

      //unlink function return bool so you can use it as conditon

      if(unlink($destination.$uploaded)){

 

      }

$query = mysql_query("DELETE FROM gallery WHERE Id='$Id'")

or die(mysql_error());

 

 

 

?>

Link to comment
https://forums.phpfreaks.com/topic/123502-solved-php-delete/#findComment-638150
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.