|
你好~我在練習第十章網路相簿,在取得最近的相簿編號的部份發生問題,問題是MAXid無法將參數帶入album_id,還有另一個問題,就是我照書上步驟做,但程式碼確跟書上的不同,轉頁網址也非書上的是在下段程式,而是在上面的程式區段,程式碼如下~麻煩了~謝謝 <%@LANGUAGE="VBSCRIPT" CODEPAGE="950"%> <!--#include file="Connections/connData.asp" --> <% ' *** 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
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME")) If (Request.QueryString <> "") Then MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString) End If
' boolean to abort record edit MM_abortEdit = false
' query string to execute MM_editQuery = "" %> <% ' *** Insert Record: set variables
If (CStr(Request("MM_insert")) = "form1") Then
MM_editConnection = MM_connData_STRING MM_editTable = "albumMain" MM_editRedirectUrl = "albumAdminFix.asp?album_id=" & MAXid MM_fieldsStr = "select|value|album_title|value|album_desc|value" MM_columnsStr = "ca_id|none,none,NULL|album_title|',none,''|album_desc|',none,''"
' create the MM_fields and MM_columns arrays MM_fields = Split(MM_fieldsStr, "|") MM_columns = Split(MM_columnsStr, "|") ' set the form values For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2 MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i))) Next
' 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 %> <% ' *** Insert Record: construct a sql insert statement and execute it
Dim MM_tableValues Dim MM_dbValues
If (CStr(Request("MM_insert")) <> "") Then
' create the sql insert statement MM_tableValues = "" MM_dbValues = "" For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2 MM_formVal = MM_fields(MM_i+1) MM_typeArray = Split(MM_columns(MM_i+1),",") MM_delim = MM_typeArray(0) If (MM_delim = "none") Then MM_delim = "" MM_altVal = MM_typeArray(1) If (MM_altVal = "none") Then MM_altVal = "" MM_emptyVal = MM_typeArray(2) If (MM_emptyVal = "none") Then MM_emptyVal = "" If (MM_formVal = "") Then MM_formVal = MM_emptyVal Else If (MM_altVal <> "") Then MM_formVal = MM_altVal ElseIf (MM_delim = "'") Then ' escape quotes MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'" Else MM_formVal = MM_delim + MM_formVal + MM_delim End If End If If (MM_i <> LBound(MM_fields)) Then MM_tableValues = MM_tableValues & "," MM_dbValues = MM_dbValues & "," End If MM_tableValues = MM_tableValues & MM_columns(MM_i) MM_dbValues = MM_dbValues & MM_formVal Next MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"
If (Not MM_abortEdit) Then ' execute the insert Set MM_editCmd = Server.CreateObject("ADODB.Command") MM_editCmd.ActiveConnection = MM_editConnection MM_editCmd.CommandText = MM_editQuery MM_editCmd.Execute MM_editCmd.ActiveConnection.Close '取得最新資料的ID值 Set RecMAX_cmd = Server.CreateObject ("ADODB.Command") RecMAX_cmd.ActiveConnection = MM_connData_STRING RecMAX_cmd.CommandText = "SELECT MAX(album_id) as maxid FROM albumMain" RecMAX_cmd.Prepared = true Set RecMAX = RecMAX_cmd.Execute RecMAX_numRows = 0 MAXid = (RecMAX.Fields.Item("maxid").Value) RecMAX.Close() Set RecMAX = Nothing
If (MM_editRedirectUrl <> "") Then Response.Redirect(MM_editRedirectUrl) End If End If
End If %> <% Dim RecWebInfo Dim RecWebInfo_numRows
Set RecWebInfo = Server.CreateObject("ADODB.Recordset") RecWebInfo.ActiveConnection = MM_connData_STRING RecWebInfo.Source = "SELECT * FROM webConfiguration" RecWebInfo.CursorType = 0 RecWebInfo.CursorLocation = 2 RecWebInfo.LockType = 1 RecWebInfo.Open()
RecWebInfo_numRows = 0 %> <% Dim RecCategory Dim RecCategory_numRows
Set RecCategory = Server.CreateObject("ADODB.Recordset") RecCategory.ActiveConnection = MM_connData_STRING RecCategory.Source = "SELECT * FROM albumCategory" RecCategory.CursorType = 0 RecCategory.CursorLocation = 2 RecCategory.LockType = 1 RecCategory.Open()
RecCategory_numRows = 0 %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=big5" /> <title></title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="page"> <div id="header"> <div id="webInfo"> <div class="webName"> </div> <div class="webDesc"> </div> <div class="webNavigation"> </div> </div> </div> <div id="sidemenu"> <h2>管理資訊 </h2> <ul> <li><a href="#">登出管理</a></li> <li><a href="adminWebInfo.asp">編輯網站資訊</a></li> </ul> <h2>管理相簿</h2> <ul> <li><a href="albumAdminCategory.asp">相簿分類管理</a></li> <li><a href="albumAdminMain.asp">管理相簿</a></li> <li><a href="albumAdminPost.asp">新增相簿</a></li> </ul> </div> <div id="content"> <h1><a href="#">管理相簿</a></h1> <div id="commentform"> <form ACTION="<%=MM_editAction%>" id="form1" name="form1" method="POST"> <h2>新增相簿</h2> <table border="0" align="center" cellpadding="10" cellspacing="0" bgcolor="#F0F0F0"> <tr> <th valign="baseline">分類</th> <td valign="baseline"><select name="select"> <% While (NOT RecCategory.EOF) %> <option value="<%=(RecCategory.Fields.Item("ca_id").Value)%>"><%=(RecCategory.Fields.Item("ca_name").Value)%></option> <% RecCategory.MoveNext() Wend If (RecCategory.CursorType > 0) Then RecCategory.MoveFirst Else RecCategory.Requery End If %> </select></td> </tr> <tr> <th valign="baseline">標題</th> <td valign="baseline"> <label> <input name="album_title" type="text" id="album_title" size="40" /> </label> </td> </tr> <tr> <th valign="baseline">內容</th> <td valign="baseline"> <textarea name="album_desc" cols="50" rows="15" id="album_desc"></textarea> </td> </tr> <tr> <th> </th> <td><label> <input name="Submit" type="submit" class="submit" value="送出" /> <input name="Submit2" type="reset" class="submit" value="重設" /> <input name="backbtn" type="button" value="回上一頁" onclick="window.history.back();" /> </label></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1"> </form> </div> <div class="postContent"></div> </div> <div id="footer"> Powered by dwAlbum@ASP v1.0 © 2006 <a href="http://www.e-happy.com.tw" target="_blank">eHappy Studio</a> All Rights Reserved</div> </div> </body> </html> <% RecWebInfo.Close() Set RecWebInfo = Nothing %> <% RecCategory.Close() Set RecCategory = Nothing %>
|