Jump to content

[SOLVED] unlink minor problem.


darkfreaks

Recommended Posts

And you put the echo immediately before the unlink? The only other thing I can think of is that you have extra characters at the beginning of $pic. Try doing a var_export($link) and a text/plain content-type:

 

<?php
  header('Content-type: text/plain;'); //Just for debugging
  ....
  var_export($link);
  //unlink($link) or die ("Could not delete file");
?>

yes with it it deletes one file at a time and errors with that error

without it does nothing and still errors.


code is:

[code

include ('config.php');
if($_POST['pics']) {
include ('config.php');
$result=mysql_query("DELETE FROM vc_pics WHERE pic='$pic'");
$result=mysql_query("DELETE FROM vc_pcomments WHERE pic='$pic'");
$link= "gallery/$pic";
unlink($pic) or die ("Could not delete file");

hmmmm maybe its something in the code its not deleting it period.

 

 

<?php

$strTitle = "Admin Activity";
define('QUADODO_IN_SYSTEM', true);
include ('includes/header2.php');

include ('config.php');
if($_POST['bulletin']) {
foreach($_POST as $id) {
include ('config.php');
mysql_query("DELETE FROM vc_bulletin WHERE id='$id'");
echo "Bulletins deleted<br>";

$date = date('l M d, Y g:i A');
$query = "INSERT INTO `vc_adminactivity` (`username`,`action`,`id`,`date`) VALUES('{$username}','Bulletins','{$id}','{$date}')";
mysql_query($query) or die(mysql_error());

mysql_close();
};
};

include ('config.php');
if($_POST['comments']) {
foreach($_POST as $id) {
include ('config.php');
mysql_query("DELETE FROM vc_comments WHERE id='$id'");
echo "Your comment(s) have been deleted<br>";

$date = date('l M d, Y g:i A');
$query = "INSERT INTO `vc_adminactivity` (`username`,`action`,`id`,`date`) VALUES('{$username}','comments','{$id}','{$date}')";
mysql_query($query) or die(mysql_error());

mysql_close();
};
};

include ('config.php');
if($_POST['contest']) {
foreach($_POST as $id) {
include ('config.php');
mysql_query("DELETE FROM vc_contest WHERE id='$id'");

echo "Entries deleted<br>";

$date = date('l M d, Y g:i A');
$query = "INSERT INTO `vc_adminactivity` (`username`,`action`,`id`,`date`) VALUES('{$username}','contest','{$id}','{$date}')";
mysql_query($query) or die(mysql_error());

mysql_close();
};
};


include ('config.php');
if($_POST['journal']) {
$result="DELETE FROM vc_journal WHERE id=$id";
$result2="DELETE FROM vc_jcomments WHERE jid=$id";
mysql_query($result)or die(mysql_error() . "<p>error: :<br>$result<p>");
mysql_query($result2)or die(mysql_error() . "<p>error: :<br>$result2<p>");
echo "Your journal(s) have been deleted<br>";

$date = date('l M d, Y g:i A');
$query2 = "INSERT INTO `vc_adminactivity` (`username`,`action`,`id`,`date`) VALUES('{$username}','journal','{$id}','{$date}')";
mysql_query($query2) or die(mysql_error());
mysql_close();

};

include ('config.php');
if($_POST['jcomments']) {
foreach($_POST as $id) {
mysql_query("DELETE FROM vc_jcomments WHERE id='$id'");
echo "Your comment(s) have been deleted<br>";

$date = date('l M d, Y g:i A');
$query = "INSERT INTO `vc_adminactivity` (`username`,`action`,`id`,`date`) VALUES('{$username}','Journal comment','{$id}','{$date}')";
mysql_query($query) or die(mysql_error());

mysql_close();
}
};

include ('config.php');
if($_POST['pcomments']) {
foreach($_POST as $id) {
mysql_query("DELETE FROM vc_pcomments WHERE id='$id'");
echo "Your comment(s) have been deleted<br>";

$date = date('l M d, Y g:i A');
$query = "INSERT INTO `vc_adminactivity` (`username`,`action`,`id`,`date`) VALUES('{$username}','pic comment','{$id}','{$date}')";
mysql_query($query) or die(mysql_error());

mysql_close();
};
};

include ('config.php');
if($_POST['videos']) {
foreach($_POST as $id) {
include ('config.php');
mysql_query("DELETE FROM vc_vids WHERE id='$id'");
echo "Video deleted<br>";

$date = date('l M d, Y g:i A');
$query = "INSERT INTO `vc_adminactivity` (`username`,`action`,`id`,`date`) VALUES('{$username}','video','{$id}','{$date}')";
mysql_query($query) or die(mysql_error());

mysql_close();
};
};

include ('config.php');
if($_POST['pics']) {
include ('config.php');
$result=mysql_query("DELETE FROM vc_pics WHERE pic='$pic'");
$result=mysql_query("DELETE FROM vc_pcomments WHERE pic='$pic'");
$link= "gallery/$pic";
unlink($link) ;
            

$date = date('l M d, Y g:i A');
$query = "INSERT INTO `vc_adminactivity` (`username`,`action`,`id`,`date`) VALUES('{$username}','picture','{$pic}','{$date}')";
mysql_query($query) or die(mysql_error());

mysql_close();
};


include ('includes/footer.php');

?>

You have several other problems with this script too...

 

First, you should just open the mysql connection once and close it once

Also, serveral times you use the code:

if($_POST['somekey']) {
foreach($_POST as $id) {

You are probably looking for $_POST['somekey'] in the foreach, not $_POST

 

can you post the output of

print_r($_POST);

so we can get an idea of what the data being submitted looks like?

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.