Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 11th, 2014, 06:30 AM
Registered User
 
Join Date: Aug 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Incorrect syntax ERROR

Hello,

I am a newbie in ASP, I am trying to list a specific record and update it from the db table. But I keep getting this error:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '='.
student_edit.asp, line 105
Thanks for your help.

Here is my code:
Code:
<%
function fixStr( theString )
    fixStr = replace( theString, "'", "''")
end function

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open strConnect
%>

<%
sqlString = "select * from jenny where ID =" & ID
Student name: <input type="text" name="name" value="<%=Student_name%>"><br />
Country: <input type="text" name="country" value="<%=country%>"><br />
Phone: <input type="text" name="phone" value="<%=phone%>"><br />
Email: <input type="text" name="email" value="<%=email%>"><br />

<%
sqlString = "update jenny set " &_
    "Student name ='" & fixStr( Student_name ) & "', " &_
    "Country ='" & fixStr( Country ) & "', " &_
    "Phone ='" & fixStr( Phone ) & "', " &_
    "Email ='" & fixStr( Email ) & "' where ID =" & ID

    dbCon.Execute sqlString
%>
http://www.anvienonline.com/
 
Old August 11th, 2014, 08:44 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Hi there. A tip for you to get the most help from forums. You need to point out what line 105 is. If your code had been 200 lines long I would not have looked at it. If you point out the offending line of code its very easy for people tot help you....

Also if the offending line can be written to the browser. Write it, run the browser and also post it also.

The most obvious mistake in your code is not closing the ASP delimiter after the 'select * from jenny' line and before the 'Student name:'

What else have I done to your code:
- your fix string function is a bit weak. You should use the one I have given you below it does a bit more. Its fairly obvious what the changes do
- It a good practice to always place a trailing semicolon after all SQL statements
- Sorry, I just don't like your spaces inside the round brackets however this will not cause error

Code:
<%
Function fixStr(theString)
    fixStr = ""
    fixStr = CStr(theString)
    if(len(fixStr) > 0) Then
      fixStr = Replace(fixStr, """", "&quot;", 1, -1, 1)
      fixStr = Replace(fixStr, "'", "''", 1, -1, 1)
      fixStr = Replace(fixStr, vbCrLf, "<BR>", 1, -1, 1)
    end if
End Function

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open strConnect

sqlString = "select * from jenny where ID = " & ID & ";"
%>

Student name: <input type="text" name="name" value="<%=Student_name%>"><br />
Country: <input type="text" name="country" value="<%=country%>"><br />
Phone: <input type="text" name="phone" value="<%=phone%>"><br />
Email: <input type="text" name="email" value="<%=email%>"><br />

<%
sqlString = "update jenny set " &_
    "Student name ='" & fixStr(Student_name) & "', " &_
    "Country ='" & fixStr(Country) & "', " &_
    "Phone ='" & fixStr(Phone) & "', " &_
    "Email ='" & fixStr(Email) & "' where ID =" & ID & ";"
    dbCon.Execute sqlString
%>
So, run this code. You error is more than likely in your second SQL statement since you are not even executing the first one!. place a response.write sqlString underneath the statment. make sure this is before the .execute. Then run the browser. Post the offending sql. I would say there is an issue with one of the values in your variables
__________________
Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Incorrect Syntax Error. binici ASP.NET 2.0 Basics 2 January 12th, 2007 01:33 AM
Error: Line 8: Incorrect syntax near '.' ; Help! Fly4High SQL Server 2000 2 August 15th, 2006 03:02 AM
Incorrect syntax near '!' sinapra Classic ASP Databases 8 August 25th, 2004 02:15 AM
Error Line 1: Incorrect syntax near '='. Calibus Classic ASP Databases 9 July 20th, 2004 02:22 PM
Incorrect syntax...... Adam H-W Classic ASP Databases 8 June 21st, 2004 11:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.