Why i am not able to delete the files(PHP)?
<p>I use a form where i have listed the data from database like title, date etc. from the database and using checkboxes i use the multiple delete operation</p>

<p>For example my code look like this </p>

<pre><code>&lt;form method="post" action="action.php"&gt;
&lt;input name="checkbox[]" type="checkbox" id="checkbox[]" value="&lt;?php echo $row['id']; ?&gt;"/&gt;
&lt;input name="delete" type="submit" id="delete" value="Delete"/&gt;
</code></pre>

<p>and in the action.php the code is like this</p>

<pre><code> $checkbox = $_POST['checkbox'];
    //count the number of selected checkboxes in an array
    $count = count($checkbox);
    //Create a for loop to delete 
    for($i=0;$i&lt;$count;$i++)   {
    $del_id = $checkbox[$i];
    $sql = "DELETE FROM news WHERE id='$del_id'";
    $result_delete_data = mysql_query($sql);
    }
</code></pre>

<p>Now the table i want to delete actually have 5 table entities like title, timestamp,pic_title,pic_brief,pic_detail the last three entities i.e pic_title, pic_brief and pic_detail is actually storing the path of the image for example the value stored in one of the 3 entity would look like this <code>upload/file/pic_title1.jpg</code>  </p>

<p>My problem is when i run my first for loop it successfully deletes the table without any problem but the file which exist in the file directory remains intact. i want to delete that file too, to remove that file i thought of adding another for loop which i did something like this</p>

<pre><code>for($j=0;$j&lt;$count;$j++){
        $delete_id = $checkbox[$j];
        $query = "SELECT news.pic_title, news.pic_brief, news.pic_detail FROM news WHERE id = '$delete_id'";
        $result = mysql_query($query);
        $row = mysql_fetch_array($result);
        unlink($row['pic_title']);
        unlink($row['pic_brief']);
        unlink($row['pic_detail']);
        }
</code></pre>

<p>The above code is unable to delete the requested file, my Query string is perfectly working fine i tested it by removing the unlink function and printing the values, it prints all the selected value , but it is refusing to delete the file and when i try to run the loop it shows error in the last three line, while i am pretty sure that, $row['pic_title'], $row['pic_brief'], $row['pic_brief'], have the full path of the image.</p>

<pre><code>    unlink($row['pic_title']);
    unlink($row['pic_brief']);
    unlink($row['pic_brief']);
</code></pre>

<p>where i am going wrong?</p>

<p>P.S: There is nothing wrong with file permission because when i individually try to run the function unlink it deletes the file from the same directory.</p>

<p>EDIT : This is the error message i get</p>

<pre><code>Warning: unlink() [function.unlink]: No error in C:\wamp\www\bn\admin-login\action.php on line 580

Warning: unlink() [function.unlink]: No error in C:\wamp\www\bn\admin-login\action.php on line 581

Warning: unlink() [function.unlink]: No error in C:\wamp\www\bn\admin-login\action.php on line 582
</code></pre>

<p>To be more precise i tested this function individually in php and it is working perfectly fine</p>

<pre><code>$target = 'upload/file/file1.jpg';
unlink($target);
</code></pre>

<p>and for this reason i dont think the file permission is causing the error, i guess i am going wrong somewhere with the logic.</p>

<p>@Lekensteyn got me the solution, thank you  Lekensteyn. </p>

<p>actually i had to first hold the value in a variable and then unlink the file. the working code looks like this.</p>

<pre><code> for($j=0;$j&lt;$count;$j++){
        $delete_id = $checkbox[$j];
        $query = "SELECT * FROM news WHERE id = '$delete_id'";
        $result = mysql_query($query);
        $row = mysql_fetch_array($result);
        $pic_title = $row['pic_title'];
        $pic_brief = $row['pic_brief'];
        $pic_detail = $row['pic_detail'];
        unlink($pic_title);
        unlink($pic_brief);
        unlink($pic_detail);
        }
</code></pre>
