Jurik Posted October 12, 2006 Share Posted October 12, 2006 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]<?phpif (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 More sharing options...
talreja_sapna Posted October 12, 2006 Share Posted October 12, 2006 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 Link to comment https://forums.phpfreaks.com/topic/23752-database-unlink-code/#findComment-107874 Share on other sites More sharing options...
redarrow Posted October 12, 2006 Share Posted October 12, 2006 should of worked i think the capital f in testFile might be wrong cheak ok. Link to comment https://forums.phpfreaks.com/topic/23752-database-unlink-code/#findComment-107878 Share on other sites More sharing options...
Jurik Posted October 12, 2006 Author Share Posted October 12, 2006 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]<?phpif (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 More sharing options...
talreja_sapna Posted October 12, 2006 Share Posted October 12, 2006 select code should be first then delete because if first we will delete the record then how we can find the filename Link to comment https://forums.phpfreaks.com/topic/23752-database-unlink-code/#findComment-107888 Share on other sites More sharing options...
Jurik Posted October 12, 2006 Author Share Posted October 12, 2006 [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 More sharing options...
talreja_sapna Posted October 12, 2006 Share Posted October 12, 2006 This code might help u<?phpif (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 More sharing options...
Jurik Posted October 12, 2006 Author Share Posted October 12, 2006 [quote author=talreja_sapna link=topic=111291.msg450944#msg450944 date=1160659903]This code might help u<?phpif (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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.