Jump to content

Database unlink code


Jurik

Recommended Posts

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

[quote]<?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.";

?>[/quote]

So far ir deletes the database entry but not the file can anyone help?
Link to comment
https://forums.phpfreaks.com/topic/23752-database-unlink-code/
Share on other sites

ok I think ive done that but im gettting

[quote]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
[/quote]

Heres the code I am running to get this

[quote]<?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.";

?>[/quote]

Any ideas?
Link to comment
https://forums.phpfreaks.com/topic/23752-database-unlink-code/#findComment-107885
Share on other sites

[quote author=talreja_sapna link=topic=111291.msg450933#msg450933 date=1160658702]
select code should be first then delete because if first we will delete the record then how we can find the filename

[/quote]

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
Link to comment
https://forums.phpfreaks.com/topic/23752-database-unlink-code/#findComment-107892
Share on other sites

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.";

?>
Link to comment
https://forums.phpfreaks.com/topic/23752-database-unlink-code/#findComment-107899
Share on other sites

[quote author=talreja_sapna link=topic=111291.msg450944#msg450944 date=1160659903]
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.";

?>

[/quote]

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

[quote]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>
[/quote]
Link to comment
https://forums.phpfreaks.com/topic/23752-database-unlink-code/#findComment-107904
Share on other sites

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.