%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
Click " _ & "here to go back to record list.
" DBConnect = "Driver={MySQL ODBC 3.51 Driver}; Server= localhost; Database=datacollector; User Id=root; Password=s@monbay;" Select Case LCase(Trim(Request.QueryString("action"))) Case "add" %> <% Case "savedata" Set cnn = CreateObject("ADODB.Connection") 'cnn.ConnectionString = AccessConnect cnn.open DBConnect image = request.form("image") image = CStr(Replace(image, "'", "''")) thumb = request.form("thumb") thumb = CStr(Replace(thumb, "'", "''")) title=request.form("title") title = CStr(Replace(title, "'", "''")) designer=request.form("designer") designer = CStr(Replace(designer, "'", "''")) story=request.form("story") story = CStr(Replace(story, "'", "''")) credits=request.form("credits") credits = CStr(Replace(credits, "'", "''")) order=request.form("order") order = CStr(Replace(order, "'", "''")) str="INSERT INTO archive (image, thumb, title, designer, story, credits, displayOrder) " str = str & "values (" str = str & "'" & image & "'" str = str & ", " str = str & "'" & thumb & "'" str = str & ", " str = str & "'" & title & "'" str = str & ", " str = str & "'" & designer & "'" str = str & ", " str = str & "'" & story& "'" str = str & ", " str = str & "'" & credits& "'" str = str & ", " str = str & "'" & order& "'" str = str & ");" cnn.Execute str, lngRecsAffected, adCmdText Or adExecuteNoRecords cnn.close Response.Write(BACK_TO_LIST_TEXT) Case "delete" ' Get the id to delete iRecordId = Request.QueryString("id") If IsNumeric(iRecordId) Then iRecordId = CLng(iRecordId) Else iRecordId = 0 End If strSQL = "DELETE FROM archive WHERE id=" & iRecordId & ";" Set cnn = Server.CreateObject("ADODB.Connection") cnn.Open DBConnect cnn.Execute strSQL, adAffectAll, adExecuteNoRecords cnn.Close Set cnn = Nothing ' We assume all is fine. Notice that we really don't ' check that anything was done... we just assume ' so since no error was thrown. For example... if ' you enter an id that's not really in the DB, the ' script runs fine, but nothing gets deleted. Response.Write("Record Id #" & iRecordId & " deleted!") Response.Write(BACK_TO_LIST_TEXT) Case "edit" ' First of a 2 part process... build a form with the ' values from the db. iRecordId = Request.QueryString("id") If IsNumeric(iRecordId) Then iRecordId = CLng(iRecordId) Else iRecordId = 0 End If strSQL = "SELECT * FROM archive WHERE id=" & iRecordId & ";" Set rs = Server.CreateObject("ADODB.Recordset") rs.Open strSQL, DBConnect, adOpenKeyset, adLockOptimistic, adCmdText If Not rs.EOF Then %>Note: Watch your input... the text field is small and no error handling is done to check for valid integers or dates. If an error gets thrown when you submit simply hit back and fix the offending entry before resubmitting.
<% Else Response.Write "Record not found!" End If rs.Close Set rs = Nothing Response.Write(BACK_TO_LIST_TEXT) Case "editsave" ' Part 2 of 2: Here's where we save the values that the ' user entered back to the DB. Again... no error ' handling or input checking so ' characters and invalid ' values will throw error messages. iRecordId = Request.Form("id") iRecordId = Replace(iRecordId, "'", "''") ' Date delimiter on this should be changed to # for Access strSQL = "UPDATE clippingsignup SET " _ & "first = '" & CStr(Replace(Request.Form("first"), "'", "''")) & "', " _ & "last = '" & CStr(Replace(Request.Form("last"), "'", "''")) & "', " _ & "company = '" & CStr(Replace(Request.Form("company"), "'", "''")) & "', " _ & "email = '" & CStr(Replace(Request.Form("email"), "'", "''")) & "', " _ & "relationship = '" & CStr(Replace(Request.Form("relationship"), "'", "''")) & "' " _ & "WHERE (id = " & iRecordId & ")" ' If something does throw an error, checking this is ' actually a valid command often helps debug. 'Response.Write strSQL Set cnn = Server.CreateObject("ADODB.Connection") cnn.Open DBConnect cnn.Execute strSQL, adAffectAll, adCmdText Or adExecuteNoRecords cnn.Close Set cnn = Nothing Response.Write("Record Id #" & iRecordId & " updated!
") Response.Write(BACK_TO_LIST_TEXT) Case Else ' view 'Create the Connection object Set cnn = CreateObject("ADODB.Connection") Set rs = CreateObject("ADODB.Recordset") 'Assign the string to the connection string property of the Connection object. cnn.ConnectionString = DBConnect cnn.open() rs.ActiveConnection = cnn SQLstring = "SELECT * FROM archive;" rs.Open SQLstring %>Image Name: |
<%= rs.Fields("image").Value %>
|
Description | Credits | ||
ID |
<%= rs.Fields("story").Value %> | <%= rs.Fields("credits").Value %> | |||
Display order |
<%= rs.Fields("displayOrder").Value %> | ||||
Show |
<%= rs.Fields("show").Value %> | ||||
Show year |
<%= rs.Fields("showyear").Value %> | ||||
Title |
<%= rs.Fields("title").Value %> | ||||
Designer |
<%= rs.Fields("designer").Value %> | ||||