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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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.";?> Quote Link to comment 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.