Jump to content


Photo

Database unlink code


  • Please log in to reply
7 replies to this topic

#1 Jurik

Jurik
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 12 October 2006 - 12:19 PM

Hi guys was wondering if you could help me, im trying to get unlink to get the name of the file I want deleted from my videos database the name of the video has been sorted in the Videofile entry. At the moment I have got unlink to work at deleting files when I specify the name but I cant seem to get it to work with the database.

Heres the code im using

<?php

if (isset($_GET['ID'])) {
$vidID = $_GET['ID'];
} else {
$vidID = NULL;
}

$myFile = "testFile.txt";
unlink($myFile);

$query = "DELETE FROM videos WHERE ID = ('$vidID')";

$result = mysql_query($query);

echo "The video has been deleted.";

?>


So far ir deletes the database entry but not the file can anyone help?

#2 talreja_sapna

talreja_sapna
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 12 October 2006 - 12:33 PM

first u need to run the select query to find the name of the file then use unlink(pass the name of the variable in which file name is stored) and then delete the record

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 12 October 2006 - 12:41 PM

should of worked i think the capital f in testFile might be wrong cheak ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 Jurik

Jurik
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 12 October 2006 - 01:05 PM

ok I think ive done that but im gettting

Warning: unlink(29): No such file or directory in c:\documents and settings\administrator\my documents\web pages\st john fisher movie front end\delete.php on line 30


Heres the code I am running to get this

<?php

if (isset($_GET['ID'])) {
$vidID = $_GET['ID'];
$Vidfile = $_GET['ID'];
} else {
$vidID = NULL;
$Vidfile = NULL;
}

$query = "DELETE FROM videos WHERE ID = ('$vidID')";
$result = mysql_query($query);

$query2 = "SELECT * FROM videos WHERE Videofile = ('$Vidfile')";
unlink($Vidfile);


echo "The video has been deleted.";

?>


Any ideas?

#5 talreja_sapna

talreja_sapna
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 12 October 2006 - 01:11 PM

select code should be first then delete because if first we will delete the record then how we can find the filename


#6 Jurik

Jurik
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 12 October 2006 - 01:15 PM

select code should be first then delete because if first we will delete the record then how we can find the filename


A very good point, sorry I really need some sleep. Anyways I tried that and am getting the same msg except the on line has moved up

#7 talreja_sapna

talreja_sapna
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 12 October 2006 - 01:31 PM

This code might help u

<?php

if (isset($_GET['ID'])) {
  $vidID = $_GET['ID'];
  $Vidfile = $_GET['ID'];
} else {
  $vidID = NULL;
  $Vidfile = NULL;
}
$query2 = "SELECT * FROM videos WHERE ID = ('$vidID')";
$result=mysql_query($query2);
while($row=mysql_fetch_array($result)
{
extract($row);
//for example if ur field name is $filename
    unlink($filename);
}

$query = "DELETE FROM videos WHERE ID = ('$vidID')";
$result = mysql_query($query);


echo "The video has been deleted.";

?>


#8 Jurik

Jurik
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 12 October 2006 - 01:54 PM

This code might help u

<?php

if (isset($_GET['ID'])) {
  $vidID = $_GET['ID'];
  $Vidfile = $_GET['ID'];
} else {
  $vidID = NULL;
  $Vidfile = NULL;
}
$query2 = "SELECT * FROM videos WHERE ID = ('$vidID')";
$result=mysql_query($query2);
while($row=mysql_fetch_array($result)
{
extract($row);
//for example if ur field name is $filename
    unlink($filename);
}

$query = "DELETE FROM videos WHERE ID = ('$vidID')";
$result = mysql_query($query);


echo "The video has been deleted.";

?>


hhhmmm just to be a pain this code generates a parse error which is on line  28 aparently, this is what is on that line and after it

extract($row);
  unlink($Videofile);
}

$query = "DELETE FROM videos WHERE ID = ('$vidID')";
$result = mysql_query($query);


echo "The video has been deleted.";

?>

<p align="center"><a href="delvideo.php">Back To Video Removal Facility </a></p>

</body>
</html>






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users