When the link is clicked this function is put into place. The purpose of this function is to delete the image and PDF file from my website's folders, and remove the specified row from my MSSQL table. This function only removes the image and PDF from the folders but does not delete the row.

Here is the function's code:

if ($_GET['del'] == 'true') {
   // cast id as int for security
   $product_code = $_GET['product_code'];
   $file = mssql_fetch_array(mssql_query("select product_img_name from products where id = $product_code"));
   unlink("img/$file[0]");     
   $file38 = mssql_fetch_array(mssql_query("select specsheet from products where id = $product_code"));
   unlink("specsheets/$file38[0]"); 
   // delete row from table
   $sql = "DELETE FROM products WHERE product_code = '$product_code'";
   $result = mssql_query($sql, $conn);
   } // end if del
有帮助吗?

解决方案

You have a mistake in your last WHERE condition. product_code = '$product_code' must be id = '$product_code'

Additionally, you can fetch two columns with a single query:

$row = mssql_fetch_array(mssql_query("select product_img_name, specsheet from products where id = $product_code"));
unlink("img/$row[0]");
unlink("specsheets/$row[1]");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top