Location: PHPKode > projects > PHP MySQL Address Book > addressbook/library/delimg.php
<?php
if(! isset($_SESSION['sectors'])){
    session_start();
   // include("conf/conf.php");
/*   $databaseURL = 'localhost';//$dbConf->get_databaseURL();
    $databaseUName = 'root';//$dbConf->get_databaseUName();
    $databasePWord = '';//$dbConf->get_databasePWord();
    $databaseName = 'addrnew';//$dbConf->get_databaseName();
  */
  include 'config.php';
//    $dbConf = new AAConf();
    $databaseURL =$dbhost;// 'localhost';//$dbConf->get_databaseURL();
    $databaseUName = $dbuser;//'root';//$dbConf->get_databaseUName();
    $databasePWord = $dbpass;//'';//$dbConf->get_databasePWord();
    $databaseName = $dbname;// 'addrnew';//$dbConf->get_databaseName();      
        //Set DB Info. in-session
 /*   $_SESSION['databaseURL']=$databaseURL; 
    $_SESSION['databaseUName']=$databaseUName; 
    $_SESSION['databasePWord']=$databasePWord; 
    $_SESSION['databaseName']=$databaseName;

*/

    $connection = mysql_connect($databaseURL,$databaseUName,$databasePWord);
	if (!$connection)
  {
  die('Could not connect: ' . mysql_error());
  }
        // or die ("Error while connecting to localhost");
    $db = mysql_select_db($databaseName,$connection);
        //or die ("Error while connecting to database");


/*
   $sql="INSERT INTO tblautopsy (`Species`,`Reference Number`,`Stocklist No`,`AutopsyDate`,`Autopsy Report`,`Final Conclusion`) VALUES ('$_POST[stklstno]','$_POST[refno]','$_POST[stklstno]','$_POST[adate]','$_POST[areport]','$_POST[fconclusion]')";
   
  */ 
  
  
  /*
  
  $sql="Select `imagename` from contacts WHERE id=".$_GET['ID'];
  mysql_query("SET NAMES 'utf8'");
mysql_query('SET CHARACTER SET utf8'); 
if (!mysql_query($sql,$connection))
  {
  die('Error: ' . mysql_error());
  }
  
$result = mysql_query($sql);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$newimgdat="";
if (trim($row['imagename'])!=="")
{
unlink("../uploads/".$_GET['nam']);
	$indimg = explode(",", trim($row['imagename']));
	for($i = 0; $i< count($indimg); $i++)
		{
			if (trim($indimg[$i])!=="" AND trim($indimg[$i])!==$_GET['nam'])
			{
				if (trim($newimgdat)!=="")
				{
				$newimgdat=$newimgdat.",".trim($indimg[$i]);
				}
				else
				{
				$newimgdat=trim($indimg[$i]);
				}
			}
		}


//   $sql="INSERT INTO tblautopsy (`Species`,`Reference Number`,`Stocklist No`,`AutopsyDate`,`Autopsy Report`,`Final Conclusion`) VALUES ('$_POST[stklstno]','$_POST[refno]','$_POST[stklstno]','$_POST[adate]','$_POST[areport]','$_POST[fconclusion]')";
 */
 if (trim($_GET['nam'])!=="")
 {
 unlink("../uploads/".$_GET['nam']);
$sql="delete from `tblimages` WHERE `imagename`='". $_GET['nam']."' and id=".$_GET['ID'];


mysql_query("SET NAMES 'utf8'");
mysql_query('SET CHARACTER SET utf8'); 

if (!mysql_query($sql,$connection))
  {
  die('Error: ' . mysql_error());
  }
//echo "Image deleted";
    mysql_close($connection);
	
	

}
if (trim($_GET['FN'])=='s')
{
header('Location: ../wabraaddressbook.php?ID='.$_GET['ID']);
}
else
{
header('Location: ../dtaildwabraaddressbook.php?ID='.$_GET['ID']);
}
}

/*
if(! isset($_SESSION['sectors'])){
    session_start();
   // include("conf/conf.php");
//    $dbConf = new AAConf();
    $databaseURL = 'localhost';//$dbConf->get_databaseURL();
    $databaseUName = 'root';//$dbConf->get_databaseUName();
    $databasePWord = '';//$dbConf->get_databasePWord();
    $databaseName = 'addrnew';//$dbConf->get_databaseName();
        
        //Set DB Info. in-session
    $_SESSION['databaseURL']=$databaseURL; 
    $_SESSION['databaseUName']=$databaseUName; 
    $_SESSION['databasePWord']=$databasePWord; 
    $_SESSION['databaseName']=$databaseName;



    $connection = mysql_connect($databaseURL,$databaseUName,$databasePWord);
	if (!$connection)
  {
  die('Could not connect: ' . mysql_error());
  }
        // or die ("Error while connecting to localhost");
    $db = mysql_select_db($databaseName,$connection);
        //or die ("Error while connecting to database");
$sql="Select `imagename` from contacts WHERE id=".$_GET['ID'];
if (!mysql_query($sql,$connection))
  {
  die('Error: ' . mysql_error());
  }
$result = mysql_query($sql);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$newimgdat="";
if (trim($row['imagename'])!=="")
{
$indimg = explode(",", trim($row['imagename']));
for($i = 0; $i< count($indimg); $i++){
	if (trim($indimg[$i])!=="" AND trim($indimg[$i])!==$_GET['nam'])
	{
	if (trim($newimgdat)!=="")
	{
	$newimgdat=$newimgdat.",".trim($indimg[$i]);
	}
	else
	{
	$newimgdat=trim($indimg[$i]);
	}
	}
}


//   $sql="INSERT INTO tblautopsy (`Species`,`Reference Number`,`Stocklist No`,`AutopsyDate`,`Autopsy Report`,`Final Conclusion`) VALUES ('$_POST[stklstno]','$_POST[refno]','$_POST[stklstno]','$_POST[adate]','$_POST[areport]','$_POST[fconclusion]')";
 
$sql="UPDATE contacts SET `imagename`='". $newimgdat."' WHERE id=".$_GET['ID'];



if (!mysql_query($sql,$connection))
  {
  die('Error: ' . mysql_error());
  }
  else
  {
  echo "deleted";
  }
  
  }*/
?>
Return current item: PHP MySQL Address Book