Dlete buttom not connecting to delete function

Hi i have this delete buttom but somehow is not wrking with the above script i know the function and admin page works fine but the delete buttom is not connection to those fuctions any idea why??

 <?php
  
 $album_id = $_GET['albums'];
  
 $photo = mysql_query("SELECT * FROM photos WHERE album_id='$album_id'");
  
 while ($row = mysql_fetch_assoc($photo))
  
  {

      echo '<div class="imagelink">';    
  
         echo '<a href=photos/thumbs/'. $row['photo_proper'] . '  "><img class="gallery" src="photos/' . $row['photo_proper'] . ' " width="100"  height="100 " /></a>';
  
         echo '<h4 class="brand">' . $row['photo_name'] . '</h4>';
  
         echo '</div>';
  
 echo '[ <a href="admin.php?mode=deletephoto&p=' .$list[$i]['photo_id']. '">Delete</a> ]';

 

 }
 
?>

this is the admin.php

<?php
define('ROOT_DIR', './');
define('THIS_SCRIPT', 'admin');
define('PROPER', TRUE);

/**
* include common files
*/
include_once(ROOT_DIR. 'includes/common.inc.php');
include_once(ROOT_DIR. 'includes/functions_gallery.inc.php');

/**
* check user is logged in
*/
if (!$_SESSION['logged_in'])
{
	header("location:" .ROOT_DIR. "login.php");
	exit();
}

/**
* can we perform
*/
$can_perform = FALSE;
switch ($mode)
{
	case "upload" :

		if (isset($_FILES['userfile']) && isset($_POST['locations']))
		{
			$can_perform = TRUE;
		}
		break;

	case "createalbum" :
	
		if (isset($_POST['album_name']) && !empty($_POST['album_name']) && isset($_POST['locations']))
		{
			$can_perform = TRUE;
		}
		break;

	case "deletealbum" :

		$album_ids = array();
		if (isset($_GET['a']))
		{
			$album_ids[] = $_GET['a'];
		}

		$can_perform = TRUE;
		break;

	case "move" :
	case "deletephoto" :
	
		$photo_ids = array();
		if (isset($_GET['p']))
		{
			$photo_ids[] = intval($_GET['p']);
		}

		$can_perform = TRUE;
		break;
}

/**
* perform actions
*/
if ($can_perform)
{
	switch ($mode)
	{
		case "upload" :
		
			if (upload_files("photos", $_POST['locations']))
			{
				$errors->raise_error(000, "Your files have been uploaded successfully!");
			}
			break;

		case "createalbum" :
		
			if (create_album($_POST['album_name'], $_POST['locations']))
			{
			}
			break;

		case "deletealbum" :
		
			if (delete_albums($album_ids))
			{
			}
			break;

		case "move" :
		
			if (move_photo($photo_ids))
			{
			}
			break;

		case "deletephoto" :
		
			if (delete_photos($photo_ids))
			{
			}
			break;
	}
}

/**
* get data we need
*/
switch ($mode)
{
	case "upload" :
	case "createalbum" :
	case "deletealbum" :

		$locs = get_locations();
		$template->assign_vars(array(

			'LOCATIONS' => make_locations($locs))

		);
		break;
}

/**
* what file do we need
*/
switch ($mode)
{
	case "createalbum" :

		$admin_file = 'albums';
		break;

	case "upload" :

		$admin_file = 'upload';
		break;

	default :

		$admin_file = 'admin';
		break;
}

/**
* parse the file
*/
include(ROOT_DIR. "style/header.php");

$template->parse($admin_file);

include(ROOT_DIR. "style/footer.php");
?>

delete_photos

function delete_photos ($photo_ids)
{
    global $db;

    if (sizeof($photo_ids) > 0)
    {
        // select photo names for deletion
        $sql = "SELECT photo_proper
            FROM " .PHOTOS_TABLE. "
            WHERE photo_id IN (" .implode(',', $photo_ids). ")";

        $db->query($sql);

        $unlink_ids = array();
        while ($row = $db->fetch())
        {
            $unlink_ids[] = $row['photo_proper'];
        }

        // now delete the photos
        if (sizeof($unlink_ids) > 0)
        {
            $sql = "DELETE FROM " .PHOTOS_TABLE. "
                WHERE photo_id IN (" .implode(',', $photo_ids). ")";
    
            if ($db->query($sql))
            {
                // remove photo from directory
                for ($i = 0; $i < sizeof($unlink_ids); $i++)
                {
                    unlink("photos/" .$unlink_ids[$i]);
                    unlink("photos/thumbs/" .$unlink_ids[$i]);
                }
                return TRUE;
            }
        }
    }

    return FALSE;
}

I was too tired last night to notice but should this line:


echo '[ <a href="admin.php?mode=deletephoto&p=' .$list[$i]['photo_id']. '">Delete</a> ]';

be this instead:


echo '[ <a href="admin.php?mode=deletephoto&p=' .$row['photo_id']. '">Delete</a> ]';

Just that I cannot see a for loop within the code. :slight_smile:

still doenst work this how i put it

if(isset($_GET['mode'])) {
   $mode = $_GET['mode'];
} 

switch ($mode)

{
 echo '[ <a href="admin.php?mode=deletephoto&p=' .$list[$i]['photo_id']. '">Delete</a> ]';

Your script in the admin page does not collect the params for what type the mode is set to.

Add this:


if(isset($_GET['mode'])) {
   $mode = $_GET['mode'];
}

Place it above
[COLOR=#000000][COLOR=#007700]

switch ($mode)

[/COLOR][/COLOR]