Jurik Posted October 30, 2006 Share Posted October 30, 2006 Hi guys, im think im getting somewhere with me delete code now. Instead of the usual error message of erro2. Im now only getting [quote]Notice: Undefined variable: Videofile in c:\documents and settings\administrator\my documents\web pages\st john fisher movie front end v2\delete.php on line 28Warning: unlink(\\benin\Videolibrary\): Permission denied in c:\documents and settings\administrator\my documents\web pages\st john fisher movie front end v2\delete.php on line 28[/quote]Can anyone help me work out where the undefined variable is comming from? Heres my code[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><?php include "conn.inc.php"; ?><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>St John Fisher Catholic High School</title><META http-equiv=Content-Type content="text/html; charset=iso-8859-1"><META content="St John Fisher Catholic High School" name=keywords><META content="St John Fisher Catholic High School" name=description><META content="Simon Mackness-Pettit, Arutha Studios" name=Author><link type="text/css" rel="stylesheet" href="styles.css"></head><body><?phpif (isset($_GET['ID'])) { $vidID = $_GET['ID'];} else { $vidID = NULL;}$query = "SELECT * FROM videos WHERE ID = ('$vidID')";$result=mysql_query($query);while($row=mysql_fetch_array($result))//Code that makes sure a certain file can be found on the drive before it unlinks the videofileif ( file_exists( "\\\benin\\Videolibrary\\checkme_sjf.txt" ) ){//Code that goes to the drive and deletes the file. unlink("\\\benin\\Videolibrary\\" . $Videofile); //Code that deletes record from database $query2 = "DELETE FROM videos WHERE ID = ('$vidID')"; $result2 = mysql_query($query2); echo "The video has been deleted."; //Code that happens if checkme_sjf is not found on the drive } else {echo "Im afraid the drive you are trying to upload the file to is incorrect, please contact the ICT department.";}?><p align="center"><a href="delvideo.php">Back To Video Removal Facility</a></p></body></html>[/code]Thanks for any help you can offer Quote Link to comment Share on other sites More sharing options...
gmwebs Posted October 30, 2006 Share Posted October 30, 2006 Yeah... The $Videofile variable is being used on the following line...[code]<?php//Code that goes to the drive and deletes the file. unlink("\\\benin\\Videolibrary\\" . $Videofile);?>[/code]I would assume that it should be defined as the filename of the video file you are trying to delete. Do you store the filename in the database table? If so, you need to assign that value to the variable before using it. Quote Link to comment Share on other sites More sharing options...
Jurik Posted October 30, 2006 Author Share Posted October 30, 2006 [quote author=gmwebs link=topic=113207.msg459885#msg459885 date=1162205667]Yeah... The $Videofile variable is being used on the following line...[code]<?php//Code that goes to the drive and deletes the file. unlink("\\\benin\\Videolibrary\\" . $Videofile);?>[/code]I would assume that it should be defined as the filename of the video file you are trying to delete. Do you store the filename in the database table? If so, you need to assign that value to the variable before using it.[/quote]Yes the file name is stored in the database in the videos table and in there under Videofile, I thought I had assigned the value in the code as I delaire the variable in the code. How do I go about doing this then, do i simple put another quary in before the unlink? Quote Link to comment Share on other sites More sharing options...
gmwebs Posted October 30, 2006 Share Posted October 30, 2006 My first suggestion is to print out the contents of your $result variable, so that you can see the values. You would then need to assign the filename contained in the result to the $Videofile variable.[code]<?php$query = "SELECT * FROM videos WHERE ID = ('$vidID')"; //Try to always fetch the columns that you need from the table. SELECT filename, description FROM videos WHERE ID = ('$vidID')$result=mysql_query($query);print_r($result); //Print out the results from the queryexit(); //Exit the script so that you can see the output?>[/code] Quote Link to comment Share on other sites More sharing options...
Jurik Posted October 30, 2006 Author Share Posted October 30, 2006 [quote author=gmwebs link=topic=113207.msg459896#msg459896 date=1162208282]My first suggestion is to print out the contents of your $result variable, so that you can see the values. You would then need to assign the filename contained in the result to the $Videofile variable.[code]<?php$query = "SELECT * FROM videos WHERE ID = ('$vidID')"; //Try to always fetch the columns that you need from the table. SELECT filename, description FROM videos WHERE ID = ('$vidID')$result=mysql_query($query);print_r($result); //Print out the results from the queryexit(); //Exit the script so that you can see the output?>[/code][/quote]Already started doing that, strange thing is that its printing out nothing, it seems the Array is empty. Heres the code that im using.[code]<?phpif (isset($_GET['ID'])) { $vidID = $_GET['ID'];} else { $vidID = NULL;}$query = "SELECT * FROM videos WHERE ID = {$vidID}";echo "Running query ... {$query}<br>";$result = mysql_query ($query);echo "Found " . mysql_num_rows ($result) . " record(s)<br>";print ("<pre>"); print ($result); print ("</pre>");$tralala = mysql_fetch_array ($result);print ("<pre>"); print ($tralala); print ("</pre>");?>[/code]And like I said it seems to be saying the array is empty Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 30, 2006 Share Posted October 30, 2006 How is this script being invoked? Is $_GET['vivID'] set when entering?Put this code at the start of your script:[code]<?phpecho '<pre>' . print_r($_GET,true) . '</pre>';?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
Jurik Posted October 30, 2006 Author Share Posted October 30, 2006 [quote author=kenrbnsn link=topic=113207.msg459907#msg459907 date=1162209113]How is this script being invoked? Is $_GET['vivID'] set when entering?Put this code at the start of your script:[code]<?phpecho '<pre>' . print_r($_GET,true) . '</pre>';?>[/code]Ken[/quote]Well this is what its printing outArray( [ID] => 75)Running query ... SELECT * FROM videos WHERE ID = 75Found 1 record(s)Resource id #4Array Quote Link to comment Share on other sites More sharing options...
Destruction Posted October 30, 2006 Share Posted October 30, 2006 As far as I'm aware print_r() is for arrays, I think using print $tralala will appear as an empty array because it's not actually reading the array.In the code given, you haven't actually defined the $videoFile at all. You've fetched the array into $tralala and not done anything following that such as:[code]<?php$videoFile = $tralala['videoFile'];?>[/code]HTHDest Quote Link to comment Share on other sites More sharing options...
Jurik Posted October 30, 2006 Author Share Posted October 30, 2006 [quote author=Destruction link=topic=113207.msg459917#msg459917 date=1162210187]As far as I'm aware print_r() is for arrays, I think using print $tralala will appear as an empty array because it's not actually reading the array.In the code given, you haven't actually defined the $videoFile at all. You've fetched the array into $tralala and not done anything following that such as:[code]<?php$videoFile = $tralala['videoFile'];?>[/code]HTHDest[/quote]Have tried that and am still getting blank reports, this is strange Quote Link to comment Share on other sites More sharing options...
trq Posted October 30, 2006 Share Posted October 30, 2006 I would think this...[code=php:0]unlink("\\\benin\\Videolibrary\\" . $Videofile);[/code]would need to be.....[code=php:0]unlink("\\\benin\\Videolibrary\\" . $row['Videofile']);[/code] Quote Link to comment Share on other sites More sharing options...
Jurik Posted October 30, 2006 Author Share Posted October 30, 2006 [quote author=thorpe link=topic=113207.msg459922#msg459922 date=1162211648]I would think this...[code=php:0]unlink("\\\benin\\Videolibrary\\" . $Videofile);[/code]would need to be.....[code=php:0]unlink("\\\benin\\Videolibrary\\" . $row['Videofile']);[/code][/quote]That seemed ta do the job, thanks Quote Link to comment Share on other sites More sharing options...
gmwebs Posted October 30, 2006 Share Posted October 30, 2006 Sorry Jurik, my mistake... I should have told you to print the output of the $row variable, as mysql_query() returns a resource which you would then need to pass through to mysql_fetch_array() ::) 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.