Q:

How to Unlink a File from Website's Folder when MSSQL Table Row is Deleted Using PHP

I am trying to make the link <a href='{$_SERVER['PHP_SELF']}?del=true&orderid={$row['orderid']}' style='color:black;' onclick='return show_confirm();'>Delete</a>
delete the specific row from the MSSQL table using the while function. Currently, the bottom code works fine and deletes the specific row from the table, but I would now like it to unlink a file from the sharedstorage folder. The file that gets unlinked has it's filename stored in the name column for that table row. Each table row has a name column that contains a unique file's name from the file that is located in the sharedstorage folder.
My problem in simple terms is when a table row gets deleted, the file for that row in my website's sharedstorage folder remains and does not get deleted with the row.
Here is the code for when the delete link is hit for that specific row:
// delete from table
    if ($_GET['del'] == 'true') {
       // cast id as int for security
       $id = (int) $_GET['orderid'];
       // delete row from table
       $sql = "DELETE FROM shareddrive WHERE orderid = '$id'";
       $result = mssql_query($sql, $conn) or die(mssql_get_last_message());
       // select the info, ordering by usort
       $sql = "SELECT orderid, name, type FROM shareddrive ORDER BY orderid";
       $result = mssql_query($sql, $conn) or die(mssql_get_last_message());
       // initialize a counter for rewriting usort
       $job_pos_sortt = 1;
       // while there is info to be fetched...
       while ($r = mssql_fetch_assoc($result)) {
          $job_poss = $r['orderid'];
          // update the usort number to the one in the next number
          $sql = "update shareddrive SET orderid = '$job_pos_sortt' WHERE name = '$job_poss'";
          $update = mssql_query($sql, $conn) or die(mssql_get_last_message());
          // inc to next avail number
          $job_pos_sortt++;
       } // end while // end if del
    }

All help is greatly appreciated.

A:

// delete from table
    if ($_GET['del'] == 'true') {
       // cast id as int for security
       $id = (int) $_GET['orderid'];
       // delete row from table

       $file = mssql_fetch_array(mssql_query("select name from shareddrive where orderid = $id"));
       unlink($file[0]);     

       $sql = "DELETE FROM shareddrive WHERE orderid = '$id'";
       $result = mssql_query($sql, $conn) or die(mssql_get_last_message());
       // select the info, ordering by usort
       $sql = "SELECT orderid, name, type FROM shareddrive ORDER BY orderid";
       $result = mssql_query($sql, $conn) or die(mssql_get_last_message());
       // initialize a counter for rewriting usort
       $job_pos_sortt = 1;
       // while there is info to be fetched...
       while ($r = mssql_fetch_assoc($result)) {
          $job_poss = $r['orderid'];
          // update the usort number to the one in the next number
          $sql = "update shareddrive SET orderid = '$job_pos_sortt' WHERE name = '$job_poss'";
          $update = mssql_query($sql, $conn) or die(mssql_get_last_message());
          // inc to next avail number
          $job_pos_sortt++;
       } // end while // end if del
    }

