Ciao ragazzi,
ho predisposto due pagine (1 htm e 1 asp) per permettere all'utente finale di ricercare dati in un database.
Si tratta di un catalogo libri.
Vi posto il codice della pagina htm:
e quello della pagina asp:codice:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Form di ricerca in catalogo libri</title> <style type="text/css"> <!-- body,td,th { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000066; font-weight: bold; } body { background-color: #FFFFFF; } --> </style></head> <body> FORM DI RICERCA IN CATALOGO LIBRI <form name="form1" method="post" action="RisultatoBiblioteca-LIBRI.asp"> CODICE <input name="cod_libri" type="text" id="cod_libri"> PAROLE CHIAVE <input name="pc_libri" type="text" id="pc_libri"> AUTORE <input name="aut_libri" type="text" id="aut_libri"> TITOLO <input name="tit_libri" type="text" id="tit_libri"> IN <input name="in_libri" type="text" id="in_libri"> VOLUME, TOMO, EDIZIONE <input name="vol_libri" type="text" id="vol_libri"> ANNO <input name="anno_libri" type="text" id="anno_libri"> LUOGO DI EDIZIONE <input name="luogo_libri" type="text" id="luogo_libri"> CASA EDITRICE <input name="ed_libri" type="text" id="ed_libri"> ISBN <input name="isbn_libri" type="text" id="isbn_libri"> NOTE <input name="note_libri" type="text" id="note_libri"> COLLOCAZIONE <input name="coll_libri" type="text" id="coll_libri"> <input name="Submit_libri" type="submit" id="Submit_libri" value="Ricerca nel catalogo LIBRI"> <input name="cancella_libri" type="reset" id="cancella_libri" value="Cancella"> </form> </body> </html>
Quando effettuo una ricerca di prova è come se mi venissero mostrati tutti i record del database, e non solo quelli che effettivamente corrispondono alla ricerca che ho fatto...codice:<html> <head> <title>RISULTATO RICERCA IN CATALOGO LIBRI</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <table width="1376" border=1> <tr><td>ID</td> <td>Codice</td> <td>Parole chiave</td> <td>Autore</td> <td>Titolo</td> <td>In</td> <td>Volume</td> <td>Anno</td> <td>Luogo Edizione</td> <td>Casa Editrice</td> <td>ISBN</td> <td>Note</td> </tr> <% '' Connessione al DB myDB = "..\db\cat_biblio.mdb" Set conn = Server.CreateObject("ADODB.Connection") conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(myDB) '' Creazione della stringa WHERE (campi per il filtro) sSQLWhere = "ID > 0" if Request("Codice") <> "" then sSQLWhere = sSQLWhere & " AND Codice = '" & Replace(Request("Codice"),"'", "''") & "'" end if if Request("Parole_chiave") <> "" then sSQLWhere = sSQLWhere & " AND Parole_chiave = '" & Replace(Request("Parole_chiave"),"'", "''") & "'" end if if Request("Autore") <> "" then sSQLWhere = sSQLWhere & " AND Autore = '" & Replace(Request("Autore"),"'", "''") & "'" end if if Request("Titolo") <> "" then sSQLWhere = sSQLWhere & " AND Titolo = '" & Replace(Request("Titolo"),"'", "''") & "'" end if if Request("In") <> "" then sSQLWhere = sSQLWhere & " AND In = '" & Replace(Request("In"),"'", "''") & "'" end if if Request("Volume_Tomo_Edizione") <> "" then sSQLWhere = sSQLWhere & " AND Volume_Tomo_Edizione = '" & Replace(Request("Volume_Tomo_Edizione"),"'", "''") & "'" end if if Request("Anno") <> "" then sSQLWhere = sSQLWhere & " AND Anno = '" & Replace(Request("Anno"),"'", "''") & "'" end if if Request("Luogo") <> "" then sSQLWhere = sSQLWhere & " AND LuogoEdizione = '" & Replace(Request("LuogoEdizione"),"'", "''") & "'" end if if Request("Editore") <> "" then sSQLWhere = sSQLWhere & " AND CasaEditrice = '" & Replace(Request("CasaEditrice"),"'", "''") & "'" end if if Request("ISBN") <> "" then sSQLWhere = sSQLWhere & " AND ISBN = '" & Replace(Request("ISBN"),"'", "''") & "'" end if if Request("Note") <> "" then sSQLWhere = sSQLWhere & " AND Note = '" & Replace(Request("Note"),"'", "''") & "'" end if if Request("Collocazione") <> "" then sSQLWhere = sSQLWhere & " AND Collocazione = '" & Replace(Request("Collocazione"),"'", "''") & "'" end if '' Lavoriamo sul Recordset Dim rs Set rs = Server.CreateObject("ADODB.Recordset") rs.cursorlocation = 3 ' ALBY: I nomi delle tabelle è meglio scriverli senza spazi, in caso contrario bisogna usare le parentesi quadre rs.Open "Select * from Libri where " & sSQLWhere, conn, 0, 1 do until rs.EOF %> <tr> <td><%=rs("ID")%></td> <td><%=rs("Codice")%></td> <td><%=rs("Parole_chiave")%></td> <td><%=rs("Autore")%></td> <td><%=rs("Titolo")%></td> <td><%=rs("In")%></td> <td><%=rs("Volume_Tomo_Edizione")%></td> <td><%=rs("Anno")%></td> <td><%=rs("Luogo")%></td> <td><%=rs("Editore")%></td> <td><%=rs("ISBN")%></td> <td><%=rs("Note")%></td> <td><%=rs("Collocazione")%></td> </tr> <% rs.MoveNext loop rs.Close %> </table> </html>
Come mai?![]()
![]()
(Premetto che di Asp so pochissimo)...
Grazie,
Ivy

Rispondi quotando
