Jump to content

[SOLVED] PHP unlink() & mysql delete problems


DasHaas

Recommended Posts

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

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);

?>

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>';
}
?>

Archived

This topic is now archived and is closed to further replies.

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