当链接被点击时,这个函数被放置到位。这个函数的目的是从我的网站的文件夹中删除图像和PDF文件,并从我的MSSQL表中删除指定的行。此函数仅从文件夹中删除图像和PDF,但不删除行。
下面是函数的代码:
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
最后一个WHERE条件出错。product_code = '$product_code'
必须是id = '$product_code'
此外,您可以使用一个查询获取两列:
$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]");