dsjoes 0 Report post Posted January 17, 2011 Yeah your right. I didn't look at the entire code and just pasted the whole block in. the unlink('../admin/testimonial_files/' . $row['Download']); line you can delete I think because its not needed? if you look at http://php.net/manual/en/function.unlink.php this method deletes a file and I don't remember you mentioning there was any files you also needed deleting. If you do need to delete a file as well then you can paste that line back into the loop block. Edit: I just looked at your code again and by the looks of it you only want to be deleting (unlinking) the file if the user submits a delete post right? If that is the case then you would need to do: <?php// Set Global Vars$HOST = "database";$USERNAME = "sonint99";$PASSWORD = "C2sHF9Zxq3ULXCTV";$DATABASE = "Random";$TABLE = "Testimonials";// Establish a connectionmysql_connect($HOST, $USERNAME, $PASSWORD) or die(mysql_error());mysql_select_db($DATABASE) or die(mysql_error());//==================================================================// Check if anything is posted//==================================================================if (isset($_POST['delete'])) { $sql = ("delete from $TABLE where "); for ($i = 0; $i < count($_POST['checkbox']); $i++) { if ($i != 0) { $sql.= "OR "; } $sql .= " id='" . $_POST['checkbox'][$i] . "'"; //================================================================== // Select file to unlink based on id posted //================================================================== $sql_file_unlink = "select Download from $TABLE where id = {$_POST['checkbox'][$i]}"; $result_file_unlink = mysql_query($sql_file_unlink); $row_file_link = mysql_fetch_assoc($result_file_unlink); if($row_file_link) { unlink('../admin/testimonial_files/' . $row_file_link['Download']); } //================================================================== } $result = mysql_query($sql); 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 colspan="6" align="center"><strong>Testimonials</strong> </td> </tr> <tr> <td><form name="delete" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <table width="400" border="1" cellpadding="3" cellspacing="1"> <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 $row = mysql_fetch_assoc($result); ?><?php do { ?> <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 } while ($row = mysql_fetch_assoc($result)); ?> <tr> <td colspan="6" align="center"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> </table> </form> </td> </tr> </table><?php I hope that's what you wanted. I removed some variables as it seems like they arnt being used like the delete id from the submit button. Thankyou it works Share this post Link to post Share on other sites