<% @Language="VBScript" %> <% 'Option Explicit Dim strConnection ' database connection string Dim conn ' database connection Dim rsPhoto ' photo recordset Dim rsGallery ' photoPhoto recordset Dim rsLoadPhotoListBox Dim rsLoadGalleryListBox Dim sql ' sql query 'Variables mapping the database fields Dim intPhoto_ID Dim intGallery_ID ' lists the existing galleries Dim strGallery_Name Dim strPhoto_Caption Dim strPhoto_URL Dim strFileName ' File name of the image Dim testname 'Variables used to display the database fields on the form Dim showPhoto_Caption Dim showPhoto_URL On Error Resume Next '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=; PWD=; Option=3" Set Conn = Server.CreateObject("ADODB.Connection") Conn.Open(strConnection) 'Retrieve the data from the html form fields intPhoto_ID = Int(Request.Form("txtPhotoID")) intGallery_ID = Int(Request.QueryString("qryGalleryId")) strPhoto_Caption = Request.Form("txtPhotoCaption") strPhoto_URL = Request.Form("picUpload") ' Add a new Photo to the database Sub AddPhoto(intGallery_ID, strPhoto_Caption, strPhoto_URL) sql = "INSERT INTO Photo(Gallery_ID, Caption, URL) VALUES(" & Int(intGallery_ID) & ",'" & strPhoto_Caption & "','" & strPhoto_URL & "')" response.write sql ' Call UploadPhoto() conn.Execute(sql) End Sub ' Update a Photo in the database Sub UpdatePhoto(intPhoto_ID, intGallery_ID, strPhoto_Caption, strPhoto_URL) Call UploadPhoto() sql = "UPDATE Photo SET Caption = '" & strPhoto_Caption & "', URL = '" & strPhoto_URL & "' WHERE ID = " & intPhoto_ID &" " conn.Execute(sql) End Sub ' Delete Photo from the database Sub DeletePhoto(intPhoto_ID) sql = "DELETE * FROM Photo WHERE ID = " & intPhoto_ID &";" conn.Execute(sql) End Sub 'Load the record id's into the photo listbox Function LoadPhotoListBox(intGallery_ID) sql = "SELECT ID FROM Photo WHERE Gallery_ID = " & Int(intGallery_ID) & ";" Set rsLoadPhotoListBox = conn.Execute(sql) While Not rsLoadPhotoListBox.EOF%> <% rsLoadPhotoListBox.MoveNext Wend rsLoadPhotoListBox.Close Set rsLoadPhotoListBox = Nothing End Function 'Load the record data for the selected record id Function LoadRecord(intPhoto_ID) sql = "SELECT * FROM Photo WHERE ID = " & Int(intPhoto_ID) & ";" Set rsPhoto = conn.Execute(sql) If Int(intPhoto_ID) > 0 Then If Not rsPhoto.EOF = True Then showPhoto_Caption = rsPhoto("Caption") showPhoto_URL = rsPhoto("URL") End If End If End Function 'Upload an image to the server Sub UploadPhoto() Dim theForm Set theForm = Server.CreateObject("ABCUpload4.XForm") %> <% 'If theForm.Count > 0 Then %> <% theForm.Overwrite = True %> <% Set theField = theForm.Files("picUpload") %> <% If theField.FileExists Then %> <% theField.Save theField.FileName %> <% End If 'End If End Sub 'Call the Add a new Photo function If Request.Form("txtPhotoID") = 0 And Request.Form("cmdInsert") = "Insert" Then Call UploadPhoto() Call AddPhoto(intGallery_ID, strPhoto_Caption, strPhoto_URL) End if If Request.Form("txtPhotoID") <> 0 And Request.Form("cmdUpdate") = "Update" Then Call UpdatePhoto(intPhoto_ID, intGallery_ID, strPhoto_Caption, strPhoto_URL) End if 'Load the photos for the selected gallery If Request.Form("txtPhotoID") > 0 Then Response.Write LoadRecord(intPhoto_ID) End if If Not Request.Form("txtPhotoID") ="0" And Request.Form("cmdDelete") = "Delete" Then Call DeletePhoto(intPhoto_ID) 'Response.Write Delete(intPhoto_ID) Response.Redirect "phototool.asp" End if %> Photo upload tool

Photo upload setup tool

Use this tool to create, update or delete a photo from a photo Photo

Photo List:
Caption:
Photo name: <%=showPhoto_URL%>  NEW:
     

Back to gallery tool