Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Bem, é o seguinte!! Consigo fazer o UPLOAD CERTINHO!!
Quando excluo, ele tira do BD porém o arquivo referente continua na pasta!!
Sei que é através do Unlink que vou resolver minha situação, porém não rola nunca!!
Eis o código que exclue do BD!!
Ps.: Reparem que há duas variáveis para deletar o arquivo... uma chamada "apagar" e outra como "apagarr", pois são responsáveis por apagar dados de tabelas diferentes! no caso estou tentando apagar os dados que são inseridos em apagarr.
<?php require_once('Connections/Lista.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
if ((isset($_GET['apagar'])) && ($_GET['apagar'] != "")) {
$deleteSQL = sprintf("DELETE FROM lista WHERE ID=%s",
GetSQLValueString($_GET['apagar'], "int"));
mysql_select_db($database_Lista, $Lista);
$Result1 = mysql_query($deleteSQL, $Lista) or die(mysql_error());
$deleteGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
}
if ((isset($_GET['apagarr'])) && ($_GET['apagarr'] != "")) {
$deleteSQL = sprintf("DELETE FROM lista2 WHERE id=%s",
GetSQLValueString($_GET['apagarr'], "int"));
mysql_select_db($database_Lista, $Lista);
$Result1 = mysql_query($deleteSQL, $Lista) or die(mysql_error());
$deleteGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
}
mysql_select_db($database_Lista, $Lista);
$query_Gravar = "SELECT * FROM lista";
$Gravar = mysql_query($query_Gravar, $Lista) or die(mysql_error());
$row_Gravar = mysql_fetch_assoc($Gravar);
$totalRows_Gravar = mysql_num_rows($Gravar);
mysql_select_db($database_Lista, $Lista);
$query_Recordset1 = "SELECT * FROM lista2";
$Recordset1 = mysql_query($query_Recordset1, $Lista) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<?php //**FUNÇÃO UNLINK QUE NÃO ESTÁ FUNCIONANDO!!**
$arquivo = "fotos/" . $id;
unlink($arquivo);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml%22)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p> </p>
<form id="form2" name="form2" method="post" action="">
<p>
<input name="apagarr" type="hidden" id="apagarr" value="<?php echo $row_Recordset1['id']; ?>" />
<input type="submit" name="button" id="button" value="Submit" />
</p>
<p> </p>
<p> </p>
</form>
<p> </p>
<form id="form1" name="form1" method="post" action="">
<p>
<input name="apagar" type="hidden" id="apagar" value="<?php echo $row_Gravar['ID']; ?>" />
<?php echo $row_Gravar['Endereco']; ?></p>
<p>
<?php echo $row_Gravar['Telefone']; ?> </p>
<p><?php echo $row_Gravar['Nome']; ?></p>
<p>
<input type="submit" value="Submit" />
</p>
</form>
</body>
</html>
<?php
mysql_free_result($Gravar);
mysql_free_result($Recordset1);
?>Carregando comentários...