salve atutti sono disperato sono 3 giorni che impazzisco dietro a questo codice, chi mi sà dare una mano?
Il mio primo dilemma è che quando apro la pagina appare in alto la scrittta "nessun file associato " come se il recordset2 fosse alla fine, e se ometto la riga mi da errore.
L'altro errore è che mi cancella il record nella tabella ma non fisicamente dalla cartella
posto il codice:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
' *** Edit Operations: declare variables
Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd
Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId
Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i
Dim Rep
Dim alert
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%ID_AGE = session("MM_ID")%>
<% session("ID")= request.form("ID")
%>
<%
' *** Delete Record: declare variables
if (CStr(Request("MM_delete")) = "form3" And CStr(Request("MM_recordId")) <> "") Then
MM_editConnection = MM_conn_STRING
MM_editTable = "T_Foto"
MM_editColumn = "Foto"
MM_recordId = "'" + Request.Form("MM_recordId") + "'"
MM_editRedirectUrl = "gest_foto.asp"
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
var = CStr(Request("MM_recordId"))
Dim Recordset2
Dim Recordset2_numRows
Set Recordset2 = Server.CreateObject("ADODB.Recordset")
Recordset2.ActiveConnection = MM_conn_STRING
Recordset2.Source = "SELECT Foto FROM T_Foto WHERE Riferimento = '" & var &"'"
Recordset2.CursorType = 0
Recordset2.CursorLocation = 2
Recordset2.LockType = 1
Recordset2.Open()
Recordset2_numRows = 0
if recordset2.eof then
Response.Write "Nessun file associato"
else
path = recordset2.fields.item("Foto").value
' CODICE PER ELIMINARE FISICAMENTE IL FILE DALLA DIRECTORY
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
path0= cstr(path)
path1 = mid(path0, 16)
objFSO.DeleteFile(Server.MapPath("\public\images\" &(path1)))
Set objFSO = Nothing
' FINE CODICE X ELIMINARE FISACAMENTE IL FILE
end if
%>
<%
' *** Delete Record: construct a sql delete statement and execute it
If (CStr(Request("MM_delete")) <> "" And CStr(Request("MM_recordId")) <> "") Then
' create the sql delete statement
MM_editQuery = "delete from " & MM_editTable & " where " & MM_editColumn & " = " & MM_recordId
If (Not MM_abortEdit) Then
' execute the delete
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
end if
%>
<%
Dim Recordset7
Dim Recordset7_numRows
Set Recordset7 = Server.CreateObject("ADODB.Recordset")
Recordset7.ActiveConnection = MM_conn_foto_STRING
Recordset7.Source = "SELECT Riferimento, ID_AGENTE FROM T_Prodotti Where ID_AGENTE = '"& session("MM_ID") & "'"
Recordset7.CursorType = 0
Recordset7.CursorLocation = 2
Recordset7.LockType = 1
Recordset7.Open()
Recordset7_numRows = 0
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables
Dim Recordset7_total
Dim Recordset7_first
Dim Recordset7_last
' set the record count
Recordset7_total = Recordset7.RecordCount
'set the number of rows displayed on this page
If (Recordset7_numRows < 0) Then
Recordset7_numRows = Recordset7_total
Elseif (Recordset7_numRows = 0) Then
Recordset7_numRows = 1
End If
' set the first and last displayed record
Recordset7_first = 1
Recordset7_last = Recordset7_first + Recordset7_numRows - 1
' if we have the correct record count, check the other stats
If (Recordset7_total <> -1) Then
If (Recordset7_first > Recordset7_total) Then
Recordset7_first = Recordset7_total
End If
If (Recordset7_last > Recordset7_total) Then
Recordset7_last = Recordset7_total
End If
If (Recordset7_numRows > Recordset7_total) Then
Recordset7_numRows = Recordset7_total
End If
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them per visualizzare i riferimenti
If (Recordset7_total = -1) Then
' count the total records by iterating through the recordset
Recordset7_total=0
While (Not Recordset7.EOF)
Recordset7_total = Recordset7_total + 1
Recordset7.MoveNext
Wend
' reset the cursor to the beginning
If (Recordset7.CursorType > 0) Then
Recordset7.MoveFirst
Else
Recordset7.Requery
End If
' set the number of rows displayed on this page
If (Recordset7_numRows < 0 Or Recordset7_numRows > Recordset7_total) Then
Recordset7_numRows = Recordset7_total
End If
' set the first and last displayed record
Recordset7_first = 1
Recordset7_last = Recordset7_first + Recordset7_numRows - 1
If (Recordset7_first > Recordset7_total) Then
Recordset7_first = Recordset7_total
End If
If (Recordset7_last > Recordset7_total) Then
Recordset7_last = Recordset7_total
End If
End If
%>
<% ' PER VISUALIZZARE LE FOTO
Dim Repeat7__numRows
Dim Repeat7__index
Repeat7__numRows = 5
Repeat7__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat7__numRows
%>
<html>
<head>
<title>Gestione Foto</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_valida teForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert(' ATTENZIONE! Tutti i campi sono obbligatori!!');
document.MM_returnValue = (errors == '');
}
function MM_popupMsg(msg) { //v1.0
alert(msg);
}
//-->
</script>
<style type="text/css">
<!--
@import url("shop.css");
-->
</style>
</head>
<body onLoad="<%= alert %>" bgcolor="#FFFFCC">
<table width="100%" align="center" class="titolo">
<tr><td align="left" valign="top">Benvenuto: <%=session("MM_Cliente")%> nella gestione delle foto dei tuoi immobili</td>
<td align="right" valign="bottom">
<form action="scelta_login.asp" method="post" name="Menu' Generale">
<input name="Submit2" type="submit" class="scritteLatoSx" value="Menu' Generale">
</form>
</td>
</tr>
</table>
<% ' CON QUESTO CICLO DEFINISCO CHE IL RECORDSET 1 ASSUMERE TUTTI I VALORI CHE ASSUME IL RECORDSET 7
while not recordset7.eof
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_conn_prodotti_STRING
Recordset1.Source = "SELECT Foto FROM T_Foto Where ID_AGENTE = '"& session("MM_ID") & "' and Riferimento ='"& recordset7.fields.item("Riferimento").value &"'"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<div align="left">
<table width="100%" align="center">
<tr>
<td width="10%" nowrap><font color="#990000">Riferimento</font>
<td width="10%" nowrap><font color="#990000">Inserimento Foto</font>
<td width="10%" nowrap><font color="#990000">Foto Caricate</font>
<td width="10%" nowrap><font color="#990000"></font>
<td width="10%" nowrap><font color="#990000"></font>
<td width="10%" nowrap><font color="#990000"></font>
<td width="10%" nowrap><font color="#990000"></font>
<td width="30%" nowrap><font color="#990000"></font>
</tr>
<tr>
<td width="10%" valign="top" nowrap><input name="riferimento" size="6" type="text" disabled value="<%=(Recordset7.Fields.Item("RIferimento").V alue)%>">
<input name="IDA" type="hidden" value="<%=(Recordset7.Fields.Item("ID_AGENTE").Val ue)%>"></td>
<td width="10%" valign="top" nowrap>
<form action="carica_foto.asp" method="post" enctype="multipart/form-data" name="form4">
<input name="campo_foto" type="file" id="campo_foto">
<input name="Submit3" type="submit" class="invio" value="Invia">
<input name="hiddenRif" type="hidden" id="hiddenRif" value="<%=(Recordset7.Fields.Item("Riferimento").V alue)%>">
<input name="hiddenID" type="hidden" id="hiddenID" value="<%=(Recordset7.Fields.Item("ID_AGENTE").Val ue)%>">
</form>
</td><% while not recordset1.eof%>
<td width="10%" valign="top" nowrap align="left">
<form name="form3" method="POST" action="<%=MM_editAction%>">
<input name="imageField" type="image" src="<%=(Recordset1.Fields.Item("Foto").Value)%>" align="left" height="90" width="90" border="0" disabled>
<input name="invia" type="submit" class="invio" id="invia" value="Elimina" align="left">
<input type="hidden" name="MM_delete" value="form3">
<input type="hidden" name="MM_recordId" value="<%=(Recordset1.Fields.Item("Foto").Value)%> ">
</form>
<% recordset1.movenext()
wend%>
</td><td width="70%"></td>
<% recordset7.movenext()
wend%>
</tr>
</table>
<table width="70%" align="center">
<tr>
<td width="100%"></td>
</tr>
<tr>
<td colspan="2"><div align="center"><font color="#990000" size="2">Dal
n°<%=(Recordset7_first)%> al
n°<%=(Recordset7_last)%>
su un tot di <%=(Recordset7_total)%> </font></div></td>
</tr>
</table>
</div>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
<%Recordset2.Close()
Set Recordset2 = Nothing
%>

Rispondi quotando
