Jump to content

unlink()


dsjoes

Recommended Posts

  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

Alright, I changed this up to utilize $_SESSION vars to minimize the number of queries, and I think this should work. I haven't tested it, but there aren't any parse errors, so try it and see how it goes. It will need some error handling added at some point.

 

<?php
session_start();
// Set Global Vars
$HOST = "XXXXXXX";
$USERNAME = "XXXX";
$PASSWORD = "XXXXX";
$DATABASE = "XXXXX";
$TABLE = "testdocs";
// Establish a connection
mysql_connect($HOST, $USERNAME, $PASSWORD) or die(mysql_error());
mysql_select_db($DATABASE) or die(mysql_error());

if( $_POST['submitted'] == 'yes') {
if( !empty($_POST['checkbox']) ) {
	foreach( $_POST['checkbox'] as $id ) {
		$query = "DELETE FROM `$TABLE` WHERE `id` = " . mysql_real_escape_string($id) . " LIMIT 1";
		if( mysql_query($query) ) {
			if( file_exists("../admin/testimonial_files/{$_SESSION['file'][$id]}") ) {
				unlink( "../admin/testimonial_files/{$_SESSION['file'][$id]}" );
				unset( $_SESSION['file'][$id] );
			}
		}
	}
}
header('Location: index.php');
exit();
} else {
// select sql here
$sql = "select * from `$TABLE` order by `id`;";
$result = mysql_query($sql);
}
?>
<table  align="center" width="400" border="0" cellspacing="1" cellpadding="0">
    <tr>
        <td><form name="delete" method="post" action="">
                <table width="400" border="1" cellpadding="3" cellspacing="1">
                    <tr>
                        <td colspan="6" align="center"><strong>Testimonials</strong> </td>
                    </tr>
                    <tr>
                        <td align="center"><strong>Select</strong></td>
                        <td align="center"><strong>ID</strong></td>
                        <td align="center"><strong>Name</strong></td>
                        <td align="center"><strong>Description</strong></td>
                        <td align="center"><strong>Download</strong></td>
                        <td align="center"><strong>Last Modified</strong></td>
                    </tr><?php while( $row = mysql_fetch_assoc($result) ) {
                    	$_SESSION['file'][$row['id']] = $row['Download'] ?>
                        <tr>
                            <td align="center">
                                <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['id']; ?>">
                            </td>
                            <td align="center"><?php echo $row['id']; ?></td>
                            <td align="center"><?php echo $row['Name']; ?></td>
                            <td align="center"><?php echo $row['Message']; ?></td>
                            <td align="center"><a href="/admin/testimonial_files/<?php echo $row['Download']; ?>">Download</a></td>
                            <td align="center"><?php echo $row['Modified']; ?></td>
                        </tr>
                        <?php } ?>
                        <tr>
                            <td colspan="6" align="center"><input name="delete" type="submit" id="delete" value="Delete"></td>
                        </tr>
                    </table>
                <input type="hidden" name="submitted" value="yes">    
                </form>
            </td>
        </tr>
    </table>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.