Array Empty On Submit

Hello,

I am getting my drop down menu data from an array from the database. Were I am stuck is I am not sure how to link the “text” from the drop down menu into the query. When I click delete it should delete the image row from the database. Any help on how to delete the file will be very welcome.

Jess


<?php
include('includes/session.php');

include('includes/header.php');

include('includes/class/class.form.php');

include('includes/class/class.image.php');

include('includes/class/class.imageManager.php');



$formImageDelete = new Form('deleteimage.php', 'Delete','return CheckDelete();', '');

$imImageManager = new imageManager();

$aImageObjects = $imImageManager->getallImages();



$aImageName = array();

for($iCount=0; $iCount<count($aImageObjects);$iCount++){
    $imImage = $aImageObjects[$iCount];
    $aImageName[] = $imImage->getImageName();
}


if(isset($_POST["submit"])){
         
    $formImageDelete->setStickyData($_POST);
    
    
   $formImageDelete->checkNotEmpty("DeleteImage");

    
    
    if($formImageDelete->getValid() == true){
	
	$removeImage = new Image();
		
	$removeImage->removeImage($_POST["DeleteImage"]);
	
	$Message = "Image Deleted";
	
    
    }else{
	
	$Message = "Error";
    }
    

}


$formImageDelete->openFieldset();
$formImageDelete->makeDropDownList("Delete","DeleteImage",$aImageName);
$formImageDelete->makeSubmitButton("submit","Delete");
$formImageDelete->closeFieldset();

$newNavigation = new Navigation();

?>

    <?php echo $newNavigation->mainMenu();?>
    
    
       	<h1  class="Heading">Delete Image</h1>
	
	<?php echo $Message; ?>
        
        <?php echo $formImageDelete->getHTML();?>
        
    
<?php include('includes/footer.php') ?>

Image Class


<?php

require_once('../includes/database.php');

class Image{
    
    private $iID;
    
    private $sImageName;
    
    private $sImagePath;
    
    public function loadImage($iID){
        
        global $database;
        
        $Query = "SELECT * FROM Gallery WHERE id =" .$iID;
        
        $resResult = $database->query($Query);
    
        //Fetch The Row
        
        $aImage = $database->fetch_array($resResult);
        
        $this->iID = $aImage["id"];
        $this->sImageName = $aImage["imageName"];
        $this->sImagePath = $aImage["imagePath"]; // Was get maybe typo
        
        $this->bExisting = true;
    
    }
    
    public function saveImage(){
        
        global $database;
        
        if($this->bExisting == false){
            
            $Query = "INSERT INTO Gallery(id,imageName,imagePath) VALUES ('".$this->iID."', '".$this->sImageName."','".$this->sImagePath."')";
            
            $bResult = $database->query($Query);
            
            if($bResult){
                
                $this->iID = $database->get_last_insert_id();
                
                $this->bExisting = true;
                
            }
            else{
                
                die("Save Failed");
            }
            
        }
    }
    
    public function removeImage(){
    
         global $database;
        
        $Query = "DELETE FROM Gallery WHERE id =".$this->iID;
        
        $resResult = $database->query($Query);
    
    
        //Fetch The Row
        
        $aImage = $database->fetch_array($resResult);
        
        $this->iID = $aImage["id"];
        $this->sImageName = $aImage["imageName"];
        $this->sImagePath = $aImage["imagePath"];    
    }
        
    
    
                // Get Functions
        
    public function getImageID(){
            return $this->iID;
    }    
        
    public function getImageName(){
            return $this->sImageName;
    }
    
    public function getImagePath(){
            return $this->sImagePath;
    }
        
    // Set Functions
    
    public function setImageID($iID){
        
        global $database;
        
        $iID = $database->escape_value($iID);
        
        $this->iID = $iID;
    }    
        
      
    public function setImageName($sImageName){
        
        global $database;
        
        $sImageName = $database->escape_value($sImageName);
        
        $this->sImageName = $sImageName;
    }   
        
    public function setImagePath($sImagePath){
        
        global $database;
        
        $sImagePath = $database->escape_value($sImagePath);
        
        $this->sImagePath = $sImagePath;
    }
    
    
}


//Testing

//Save

//$newImageUpload = new Image();
//$newImageUpload->setImageID(8);
//$newImageUpload->setImageName("Image Class Works");
//$newImageUpload->setImagePath("Image Path Success");
//$newImageUpload->saveImage();



?>



it’s not clear to me from your code exactly what is going on, but if you want to delete multiple images in one go, then I would suggest something along these lines

  1. generate a “delete” checkbox in your html form for each row of data retrieved from the database.
 
<?php
 
while($row=mysql_fetch_assoc($rs)) {
        echo '<input type="checkbox" name="delMe[]" value="'.$row['someID'].'" />';
 
}
?>

where someID is the id of the row in the database.

  1. create a “Delete selected items” button in your form.

  2. when the button in 2) is clicked an array of id’s to delete, called delMe, will be sent to the server side script.

  3. the server side script will receive the id’s to delete in $_POST[‘delMe’]

  4. process the array in 4) to delete the selected id’s from the database

 
<?php
 
$rows2Del = $_POST['someID'];
foreach($rows2Del as $id) {
      $query = 'delete from myTable where fldID = "'.$id.'"';
      //then run the query
}
 
?>