182x Posted July 19, 2007 Share Posted July 19, 2007 Hey guys, the following code removes a record from the database but it wont remove the file related to the record which is obtained form the fileLocation field which is a path such as ../files/test.doc. I was just wondering how to fix this? Thanks. $del="SELECT fileLocation FROM em WHERE emp = $pr"; $re = mysql_query($de, $link_id)or die(mysql_error()); $g=mysql_fetch_array($re); if (empty($g)) { $de="DELETE FROM em WHERE emp = $pr; $re= mysql_query($de, $link_id)or die(mysql_error()); } else{ $de="DELETE FROM em WHERE emp = $pr"; $re = mysql_query($de, $link_id)or die(mysql_error()); unlink($g); } Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted July 19, 2007 Share Posted July 19, 2007 are u getting an error, r u sure the filepath is valid relative to the script? Quote Link to comment Share on other sites More sharing options...
clearstatcache Posted July 19, 2007 Share Posted July 19, 2007 try to print the path to check if its rily valid path... Quote Link to comment Share on other sites More sharing options...
182x Posted July 19, 2007 Author Share Posted July 19, 2007 Thanks for the replies, It does remove the record from the database just not the file. How do I print out the name as it is in an array, I tried using echo but I kept getting syntax errors. Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 19, 2007 Share Posted July 19, 2007 mysql_fetch_array returns a associative array so unlink($g["fileLocation"]); Quote Link to comment Share on other sites More sharing options...
182x Posted July 19, 2007 Author Share Posted July 19, 2007 Thanks, It still doesn't remove the file just removes the database record as before. Anymore suggestions? Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 19, 2007 Share Posted July 19, 2007 Try debugging it by putting after the unlink statement print_r($g); then post all the data it prints. Quote Link to comment Share on other sites More sharing options...
182x Posted July 19, 2007 Author Share Posted July 19, 2007 Just gave it a try nothing was displayed Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 19, 2007 Share Posted July 19, 2007 Well that means that fileLocation in your mysql table contains no data. maybe show us the rows in your table that your trying to delete. Quote Link to comment Share on other sites More sharing options...
182x Posted July 19, 2007 Author Share Posted July 19, 2007 yeah thats weird though, when I check the database with phpmyadmin it indicates that the information is there. Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 19, 2007 Share Posted July 19, 2007 In your query SELECT fileLocation FROM em WHERE emp = $pr is it possible that fileLocation is spelled incorrectly for the corresponding column. Quote Link to comment Share on other sites More sharing options...
182x Posted July 19, 2007 Author Share Posted July 19, 2007 Thats the weird thing everything seems right. Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 19, 2007 Share Posted July 19, 2007 Well try the query directly in phpMyAdmin to see if its working. Quote Link to comment Share on other sites More sharing options...
182x Posted July 19, 2007 Author Share Posted July 19, 2007 I still can't figure this one out. Is there a chance that getting the variable from the array is wrong in terms of syntax? Quote Link to comment Share on other sites More sharing options...
dbo Posted July 19, 2007 Share Posted July 19, 2007 Can you post your most recent code? Also what kind of paths are being stored? Is it an absolute path or a relative path? Quote Link to comment Share on other sites More sharing options...
182x Posted July 19, 2007 Author Share Posted July 19, 2007 Can you post your most recent code? Also what kind of paths are being stored? Is it an absolute path or a relative path? Hi Its a relative path, it seems to be a permission error not sure how to fix this in vista and I have ensured the folder has all te necessary access rights. Quote Link to comment Share on other sites More sharing options...
dbo Posted July 19, 2007 Share Posted July 19, 2007 I wouldn't worry about permissions errors until you can prove out the fact that you're grabbing the path from the db first. Did you ever get echo $g to work? 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.