% Option Explicit Dim strConnection ' database connection string Dim conn ' database connection Dim rsGallery ' photogallery recordset Dim rsLoadGalleryListBox Dim sql ' sql query 'Variables mapping the database fields Dim intGallery_ID Dim strGallery_Name Dim strGallery_Description Dim intGallery_Active ' flag to show whether this gallery is active or not 'Variables used to display the database fields on the form Dim showGallery_Name Dim showGallery_Description Dim showGallery_Active 'Connect to the database 'strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.MapPath("photogallery.mdb") & ";" 'strConnection ="Driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.MapPath("photogallery.mdb") & ";" 'Set conn = Server.CreateObject("ADODB.Connection") 'conn.Open(strConnection) 'MySQL Connection strConnection = "Driver={MySQL ODBC 3.51 Driver}; Server=sql3de.your-server.co.za; Database=voiceofthecape; UID=vocfma_1; PWD=MJHEufA5; Option=3" Set Conn = Server.CreateObject("ADODB.Connection") Conn.Open(strConnection) 'Retrieve the data from the html form fields intGallery_ID = Int(Request.Form("txtGalleryID")) strGallery_Name = Request.Form("txtGalleryName") strGallery_Description = Request.Form("txtGalleryDescription") intGallery_Active = Request.Form("chkActive") Response.write intGallery_Active ' Add a new gallery to the database Sub AddGallery(strGallery_Name, strGallery_Description, intGallery_Active) If intGallery_Active = Null Or intGallery_Active = "" Then intGallery_Active = 0 Else intGallery_Active = 1 End If sql = "INSERT INTO gallery(Name, Description, Active) VALUES('" & strGallery_Name & "','" & strGallery_Description & "', " & intGallery_Active & ");" conn.Execute(sql) End Sub ' Update a gallery in the database Sub UpdateGallery(intGallery_ID, strGallery_Name, strGallery_Description, intGallery_Active) If intGallery_Active = Null Or intGallery_Active = "" Then intGallery_Active = 0 Else intGallery_Active = 1 End If ' sql = "UPDATE Gallery SET Name = '" & strGallery_Name & "', Description = '" & strGallery_Description & "' Active = " & intGallery_Active & " WHERE ID = " & intGallery_ID &" " Response.Write sql ' conn.Execute(sql) End Sub ' Delete gallery from the database Sub DeleteGallery(intGallery_ID) sql = "DELETE FROM gallery WHERE ID = " & intGallery_ID & ";" conn.Execute(sql) End Sub 'Load the record id's into the listbox Function LoadGalleryListBox() sql = "SELECT ID, Name FROM gallery;" Response.Write sql Set rsLoadGalleryListBox = conn.Execute(sql) While Not rsLoadGalleryListBox.EOF%> <% rsLoadGalleryListBox.MoveNext Wend rsLoadGalleryListBox.Close Set rsLoadGalleryListBox = Nothing End Function 'Load the record data for the selected record id Function LoadRecord(intGallery_ID) sql = "SELECT * FROM gallery WHERE ID = " & Int(intGallery_ID) & ";" Set rsGallery = conn.Execute(sql) If Int(intGallery_ID) > 0 Then If Not rsGallery.EOF = True Then showGallery_Name = rsGallery("Name") showGallery_Description = rsGallery("Description") showGallery_Active = rsGallery("Active") End If End If End Function 'Call the Add a new gallery function If Request.Form("txtGalleryID") = 0 And Request.Form("cmdInsert") = "Insert" Then Call AddGallery(strGallery_Name, strGallery_Description, intGallery_Active) 'Else ' If Request.Form("txtGalleryID") <> 0 And Request.Form("Submit") = "Update" Then ' Update(intGallery_ID) ' End if End if If Request.Form("txtGalleryID") <> 0 And Request.Form("cmdUpdate") = "Update" Then Call UpdateGallery(intGallery_ID, strGallery_Name, strGallery_Description, intGallery_Active) End if If Request.Form("txtGalleryID") > 0 Then Response.Write LoadRecord(intGallery_ID) End if If Not Request.Form("txtGalleryID") ="0" And Request.Form("cmdDelete") = "Delete" Then Call DeleteGallery(intGallery_ID) 'Response.Write Delete(intGallery_ID) Response.Redirect "gallerytool.asp" End if %>
Use this tool to create, update or delete a photo gallery