Multiple Checkboxes as an Array to Delete Files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

dyonak
Forum Commoner
Posts: 56
Joined: Wed Jun 22, 2005 10:22 am
Location: Minneapolis, MN
Contact:

Post by dyonak »

Code: Select all

echo $_POST['deletethese'];
	print_r ($_POST['deletethese']);
is directly below the form, above the if(issset) statement, and yields nothing.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

let's see all the code...something is awry if neither of those show anything...
dyonak
Forum Commoner
Posts: 56
Joined: Wed Jun 22, 2005 10:22 am
Location: Minneapolis, MN
Contact:

Post by dyonak »

Incoming:

Code: Select all

<?php
echo '<form><table width ="100%">';
$count = 0;
foreach (glob("imagestest/*.jpg") as $filename) {

   echo "<td width='100'><a 

href='http://www.dustinyonak.net/$filename'><img 

src='$filename' width='80' height='60'></a><br />" . 

round(filesize($filename)/1024) . "KB <input type='checkbox' 

name='deletethese[]' value='$filename'></td>";
	$count ++;
	if($count==5){
        echo "</tr><tr>";
        $count = 0;
    }

}

echo '</table>';
echo '<input type="submit" name="delsubmit" value="Delete 

Selected Images">';
echo '</form>';

//Handle the deletion form
$count = 0;

	echo $_POST['deletethese'];
	print_r ($_POST['deletethese']);
if (isset($_POST['delsubmit'])) {
	$deletethese = $_POST['deletethese'];
	foreach($deletethese as $index=>$deletethis){
		$count ++;
	}

}
echo "$count images deleted.";
The rest of the code, below this, is the upload submission form/image resizing script. In the interest of readability I didn't include that stuff but if you want ALL of the pages code let me know and I will paste it.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

try this:

Code: Select all

<?php
//Handle the deletion form
if(isset($_POST['deletethese'])){ 
    echo $_POST['deletethese'];
    print_r ($_POST['deletethese']);
}else
    echo "post vars not set yet";


echo '<form><table width ="100%">';
$count = 0;
foreach (glob("imagestest/*.jpg") as $filename) {
 
   echo "<td width='100'><a 
 
href='http://www.dustinyonak.net/$filename'><img 
 
src='$filename' width='80' height='60'></a><br />" . 
 
round(filesize($filename)/1024) . "KB <input type='checkbox' 
 
name='deletethese[]' value='$filename'></td>";
    $count ++;
    if($count==5){
        echo "</tr><tr>";
        $count = 0;
    }
 
}
 
echo '</table>';
echo '<input type="submit" name="delsubmit" value="Delete 
 
Selected Images">';
echo '</form>';
dyonak
Forum Commoner
Posts: 56
Joined: Wed Jun 22, 2005 10:22 am
Location: Minneapolis, MN
Contact:

Post by dyonak »

Just getting a whole lot of "post vars not set yet".

Here's the page with your code on it if you want to look. . .

Pic Manager
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

doh! you need to change your form method to "POST"...it is "GET" by default.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

call print_r($_POST) to see what IS being sent.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
dyonak
Forum Commoner
Posts: 56
Joined: Wed Jun 22, 2005 10:22 am
Location: Minneapolis, MN
Contact:

Post by dyonak »

That was it Burrito :oops: I'm embarrased, sorry about that you guys haha, thanks so much for all your help.
Post Reply