Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Dreamweaver (all versions) section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 17th, 2003, 11:27 AM
Authorized User
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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 &amp; 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>&nbsp;</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">&nbsp;</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>&nbsp;</p>
</body>
</html>
<%
rsPage.Close()
Set rsPage = Nothing
%>
<%
rsPageTypes.Close()
Set rsPageTypes = Nothing
%>
Reply With Quote
  #2 (permalink)  
Old July 18th, 2003, 12:59 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Are you sure that all items in your drop-down have a value? Maybe some of them is blank, causing an error.

Somewhere on the second page, you have this:

Code:
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    Change that to this:

Code:
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    Response.Write("SQL Statement is " & MM_editQuery)
    Response.End
    MM_editCmd.Execute


If you take a look at the SQL statement that Dreamweaver has generated for you, you may see where the problem is. Otherwise, post the SQL statement here, so we can take a look at it.

HtH

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #3 (permalink)  
Old July 24th, 2003, 04:38 AM
Authorized User
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ive discovered the problem... my bad :) im using SQL reserved words in my field names. whooooops!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update one record jemacc SQL Server 2000 0 September 12th, 2007 11:47 AM
not update all record mohiddin52 Access VBA 10 May 9th, 2007 11:41 AM
Update record error Dejitan ASP.NET 1.0 and 1.1 Basics 5 December 20th, 2006 10:15 AM
cannot update record keyvanjan ASP.NET 1.0 and 1.1 Basics 0 September 9th, 2006 05:25 AM
UPDATE CURRENT RECORD ranakdinesh Classic ASP Databases 6 March 18th, 2005 02:22 AM



All times are GMT -4. The time now is 04:39 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.