DasHaas Posted May 27, 2007 Share Posted May 27, 2007 Im trying to delete a file, then delete the row in my table that holds the info for this file. I tried the code below and got this error: Parse error: parse error, unexpected T_STRING in /nfs/cust/4/97/13/731794/web/Admin/backup/PXS_DeleteBackup.php on line 34 Here is my code, any help would be greatly appreciated ??? <?php include('../Includes/PXS_Conf.php'); // check for record ID if ((!isset($_GET['id']) || trim($_GET['id']) == '')) { die('Missing Backup ID!'); } // open database connection $connection = mysql_connect($host, $user, $pass) or die ('Unable to connect to MySql server! Please contact PXS customer support.'); // select database mysql_select_db($db) or die ('Unable to select database! Please contact PXS customer support.'); $id = $_GET['id']; $qry = "SELECT filename FROM PXS_BackupDesc WHERE id = '$id'"; $rst = mysql_query($qry) or die ("Error in query: $qry. " . mysql_error()); while($row = mysql_fetch_object($rst)) $filename = $row->filename unlink($filename); // generate and execute query $query = "DELETE FROM PXS_BackupDesc WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // close database connection mysql_close($connection); // print result echo '<center><a href=PXS_Restore.php>Deletion successful click here to go back to the backup list</a></center>'; ?> Link to comment https://forums.phpfreaks.com/topic/53123-solved-php-unlink-mysql-delete-problems/ Share on other sites More sharing options...
tjodolv Posted May 27, 2007 Share Posted May 27, 2007 The problem seems to be this: <?php while($row = mysql_fetch_object($rst)) $filename = $row->filename unlink($filename); ?> change it to this: <?php while($row = mysql_fetch_object($rst)) { // add this curly brace.. $filename = $row->filename; // .. and this semicolon.. } // ..and end it with this curly brace unlink($filename); ?> Link to comment https://forums.phpfreaks.com/topic/53123-solved-php-unlink-mysql-delete-problems/#findComment-262426 Share on other sites More sharing options...
DasHaas Posted May 27, 2007 Author Share Posted May 27, 2007 Thanks, I got it to work with this: <?php include('../Includes/PXS_Conf.php'); // check for record ID if ((!isset($_GET['id']) || trim($_GET['id']) == '')) { die('Missing Backup ID!'); } // open database connection $connection = mysql_connect($host, $user, $pass) or die ('Unable to connect to MySql server! Please contact PXS customer support.'); // select database mysql_select_db($db) or die ('Unable to select database! Please contact PXS customer support.'); $id = $_GET['id']; $qry = "SELECT * FROM PXS_BackupDesc WHERE id = '$id'"; $rst = mysql_query($qry) or die ("Error in query: $qry. " . mysql_error()); $row_result = mysql_fetch_assoc($rst); $path = '../backup/'.$row_result['file']; if (!unlink($path)) { echo ("Error deleting $path"); } else { // generate and execute query $query = "DELETE FROM PXS_BackupDesc WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // close database connection mysql_close($connection); // print result echo '<center><a href=PXS_Restore.php>Deletion successful click here to go back to the backup list</a></center>'; } ?> Link to comment https://forums.phpfreaks.com/topic/53123-solved-php-unlink-mysql-delete-problems/#findComment-262434 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.