dsjoes Posted January 16, 2011 Author Share Posted January 16, 2011 I'll try to look it over in detail later this evening. Don't have time at the moment, though. thanks Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/3/#findComment-1160441 Share on other sites More sharing options...
Pikachu2000 Posted January 17, 2011 Share Posted January 17, 2011 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 https://forums.phpfreaks.com/topic/223250-unlink/page/3/#findComment-1160523 Share on other sites More sharing options...
dsjoes Posted January 17, 2011 Author Share Posted January 17, 2011 the code just gives me the same errors but i have got other code working thanks Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/3/#findComment-1160670 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.