mi cancella(nella directory) solo l'ultima foto inserita nella tabella photos e non tutte, come mai?
Codice PHP:
<?php
//fetch photo name
$colname_photo = "-1";
if (isset($_GET['id'])) {
$colname_photo = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_myconn, $myconn);
$query_photo = sprintf("SELECT * FROM photos WHERE ptid = %s", $colname_photo);
//echo $query_photo;
$photo = mysql_query($query_photo, $myconn) or die(mysql_error());
$row_photo = mysql_fetch_assoc($photo);
$totalRows_photo = mysql_num_rows($photo);
$fname = $row_photo['location'];
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
mysql_select_db($database_myconn, $myconn);
/*
//fetch member id from email
$sql = "select id from members where email = '" . $_SESSION['MM_Username'] . "'";
echo $sql;
$mid = mysql_query($sql,$myconn) or die(mysql_error());
$array = mysql_fetch_assoc($mid);
$id = $array['id'];
*/
if ((isset($_GET['id'])) && ($_GET['id'] != "")) {
$deleteSQL2 = "DELETE FROM photos WHERE ptid=".$_REQUEST['id'];
//echo $deleteSQL;
//die();
mysql_select_db($database_myconn, $myconn);
$Result2 = mysql_query($deleteSQL2, $myconn) or die(mysql_error());
$deleteGoTo2 = "a_index.php?id=".$_REQUEST['id'];
header(sprintf("Location: %s", $deleteGoTo2));
}
//delete photos from file
unlink('admin/photos/uploads/'.$fname);
unlink('admin/photos/uploads/thumbs/tn_'.$fname);
unlink('admin/photos/uploads/small_thumbs/tn_'.$fname);
if ((isset($_GET['id'])) && ($_GET['id'] != "")) {
$deleteSQL = sprintf("DELETE FROM items WHERE id=%s",
GetSQLValueString($_GET['id'], "int")) . " and mid = " . $_SESSION['memberID'];
//echo $deleteSQL;
$Result1 = mysql_query($deleteSQL, $myconn) or die(mysql_error());
$deleteGoTo = "a_index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
}
?>