update record problems
Dreamweaver 6.1 and Access database
I have a page i am trying to update but I keep getting an SQL syntax error, but i can't see anything wrong. basically there is a drop down menu in a form on the first page which gives the update page the data to pull from the DB. which seems to work fine. the second page loads and when you submit the changes it says there is a syntax error. im uploading HTML tags with all this but ive never had problems befor. I know i can insert records as that is already working so i doubt its a permission issue. Any help V. much appreciated
Thanks all
This is the first page
<%@LANGUAGE="VBSCRIPT"%>
<%
Dim rsPages
Dim rsPages_numRows
Set rsPages = Server.CreateObject("ADODB.Recordset")
rsPages.ActiveConnection = MM_Learndirect_STRING
rsPages.Source = "SELECT DISTINCT page FROM pagedata"
rsPages.CursorType = 0
rsPages.CursorLocation = 2
rsPages.LockType = 1
rsPages.Open()
rsPages_numRows = 0
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>learndirect - Kingston, Merton & Richmond</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../styles/accessible.css" rel="stylesheet" type="text/css">
</head>
<body>
<table id="toptable">
<tr>
<td width="32" height="32" valign="middle"><img src="../images/templateImages/Learndirect_logo32x32.gif" width="32" height="32"></td>
<td colspan="2" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="*" height="32">
<div id="www">www.</div>
<div id="london">South West</div>
<div id="learning">Learning</div>
<div id="zone">Zone</div>
<div id="com">.co.uk</div>
</td>
</tr>
</table>
</td>
</tr>
</table><table border="0" cellpadding="0" cellspacing="0" id="maintable">
<tr><td width="20%" height="100%" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="100%" valign="top"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="100%" id="topgradient"><img src="../images/templateImages/bgCorner_01.gif" width="27" height="30"></td>
</tr>
<tr>
<td id="navigation">[list]
<li><a href="../index.asp">welcome</a></li>
<li><a href="../centreList.asp">our centres</a></li>
<li><a href="../learner.asp">learner support</a></li>
<li><a href="../skills4life.asp">skills for life</a></li>
<li><a href="../smbusiness.asp">small - medium businesses</a></li>
<li><a href="../contactus.asp">contact us</a></li>
<li><a href="../aboutus.asp">about us</a></li>
<li><a href="../computer.asp">computer skills</a></li>
<li><a href="../forum/default.asp">forum</a></li>
<li><a href="http://www.learndirect.co.uk">learndirect</a></li>
</ul></td></tr>
</table></td>
</tr>
</table></td>
<td id="content">
<p>Please choose
the page you would like to update:</p>
<form name="form1" method="post" action="updatepage.asp">
<select name="page" id="page">
<%
While (NOT rsPages.EOF)
%>
<option value="<%=(rsPages.Fields.Item("page").Value)%>">< %=(rsPages.Fields.Item("page").Value)%></option>
<%
rsPages.MoveNext()
Wend
If (rsPages.CursorType > 0) Then
rsPages.MoveFirst
Else
rsPages.Requery
End If
%>
</select>
<input name="edit" type="submit" id="edit" value="edit page">
</form>
<p> </p>
</td>
</tr>
</table>
</body>
</html>
<%
rsPages.Close()
Set rsPages = Nothing
%>
And this is the second page:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
' *** 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 & "?" & Request.QueryString
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
' *** Update Record: set variables
If (CStr(Request("MM_update")) = "form1" And CStr(Request("MM_recordId")) <> "") Then
MM_editConnection = MM_Learndirect_STRING
MM_editTable = "pagedata"
MM_editColumn = "autoID"
MM_recordId = "" + Request.Form("MM_recordId") + ""
MM_editRedirectUrl = "updatepageconfirm.asp"
MM_fieldsStr = "heading|value|content|value|page|value|date|value "
MM_columnsStr = "heading|',none,''|content|',none,''|page|',none,' '|date|',none,NULL"
' 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
%>
<%
' *** Update Record: construct a sql update statement and execute it
If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then
' create the sql update statement
MM_editQuery = "update " & MM_editTable & " set "
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_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_formVal
Next
MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId
If (Not MM_abortEdit) Then
' execute the update
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<%
Dim rsPage__MMColParam
rsPage__MMColParam = "1"
If (Request.Form("page") <> "") Then
rsPage__MMColParam = Request.Form("page")
End If
%>
<%
Dim rsPage
Dim rsPage_numRows
Set rsPage = Server.CreateObject("ADODB.Recordset")
rsPage.ActiveConnection = MM_Learndirect_STRING
rsPage.Source = "SELECT * FROM pagedata WHERE page = '" + Replace(rsPage__MMColParam, "'", "''") + "'"
rsPage.CursorType = 0
rsPage.CursorLocation = 2
rsPage.LockType = 1
rsPage.Open()
rsPage_numRows = 0
%>
<%
Dim rsPageTypes
Dim rsPageTypes_numRows
Set rsPageTypes = Server.CreateObject("ADODB.Recordset")
rsPageTypes.ActiveConnection = MM_Learndirect_STRING
rsPageTypes.Source = "SELECT pageType FROM pageTypes"
rsPageTypes.CursorType = 0
rsPageTypes.CursorLocation = 2
rsPageTypes.LockType = 1
rsPageTypes.Open()
rsPageTypes_numRows = 0
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body><h1><%=(rsPage.Fields.Item("page").Value)% ></h1>
<form method="POST" action="<%=MM_editAction%>" name="form1">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Heading:</td>
<td>
<input type="text" name="heading" value="<%=(rsPage.Fields.Item("heading").Value)%>" size="32">
</td>
</tr>
<tr>
<td nowrap align="right" valign="top">Content:</td>
<td valign="baseline">
<textarea name="content" cols="50" rows="5"><%=(rsPage.Fields.Item("content").Value)% ></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Page:</td>
<td>
<select name="page">
<%
While (NOT rsPage.EOF)
%>
<option value="<%=(rsPage.Fields.Item("page").Value)%>" <%If (Not isNull(rsPage.Fields.Item("page").Value)) Then If (CStr(rsPage.Fields.Item("page").Value) = CStr(rsPage.Fields.Item("page").Value)) Then Response.Write("SELECTED") : Response.Write("")%> ><%=(rsPage.Fields.Item("page").Value)%></option>
<%
rsPage.MoveNext()
Wend
If (rsPage.CursorType > 0) Then
rsPage.MoveFirst
Else
rsPage.Requery
End If
%>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td>
<input type="submit" value="Update Record">
</td>
</tr>
</table>
<input type="hidden" name="date" value="<%response.write(date)%>" size="32">
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="MM_recordId" value="<%= rsPage.Fields.Item("autoID").Value %>">
</form>
<p> </p>
</body>
</html>
<%
rsPage.Close()
Set rsPage = Nothing
%>
<%
rsPageTypes.Close()
Set rsPageTypes = Nothing
%>
|