Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    225
    Thanks
    2
    Thanked 0 Times in 0 Posts

    asp help for newbie 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:
    <!-- #INCLUDE VIRTUAL="connect.asp" -->
    <%
    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
    %>

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Where is ID defined?

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Regular Coder
    Join Date
    Nov 2005
    Posts
    225
    Thanks
    2
    Thanked 0 Times in 0 Posts
    ID is defined from previous page.
    thanks.

  • #4
    Regular Coder
    Join Date
    Nov 2005
    Posts
    225
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hello,
    I defined the Id by ID=request( "id" ), no more syntax errors. But it shows all blank text boxes.
    What did I do wrong?
    thanks.

  • #5
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    1st, you've left out important code. Which line is 105? We need to know that to see the error.

    2nd:
    <%
    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 />
    The above has an open ended <% with none closing. Like NikkiH stated, ID is not defined. It won't carry over from the previous page, unless it was submitted in a form, sent over the querystring, or stored in a session, in which case you'll need to use the Request method for retrieving the value. I also don't see where the Student_name, country, phone, and email variables are being set.

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

    dbCon.Execute sqlString
    %>
    The above should be at the top of your page after the form has been submitted to update the values. You would also need to retrieve those values using Request.Form. And last, it's good practice to never use spaces in your field names. If you do, you need to enclose the field with [] brackets, i.e. [Student Name]. However, it's just easier to never use spaces and use underscores instead to break up field names.

    -Shane

  • #6
    Regular Coder
    Join Date
    Nov 2005
    Posts
    225
    Thanks
    2
    Thanked 0 Times in 0 Posts
    thanks.
    It worked.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •