Results 1 to 20 of 20

Thread: Sintax error when adding a record

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    18

    Angry

    Hello, i've got a problem with adding records to a database.

    Here's the code for adding a record:

    set conn = Server.CreateObject("ADODB.Connection")
    conn.ConnectionString="DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=c:\documenti\forum.mdb"
    conn.Open
    set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open "Threads", conn, , adLockOptimistic, adCmdTable
    'You must imagine a form first
    rs.addnew
    rs("title")=request("strtitle")
    rs("from")=request.cookies("forum")("user")
    rs("text")=request("strtext")
    rs.update
    when the script calls rs.update, it's a sintax error for INSERT INTO

    why? It's because i'm adding wrong type of data in the db fields? The title is text, the from is text and the title is memo (long text)
    Or is because the table has pre-defined fields? ID is a counter and time and date have a default value of time() and date()

    Where's the mistake?

  2. #2
    Addicted Member
    Join Date
    Sep 2000
    Posts
    219
    Isn't it Request.Form("Field") ?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    18
    if you request something without specyfing the collection, asp automatically search for a querystring, if not present, it searchs for a form, then for a cookie and so on... that's not the mistake
    Please help!

  4. #4
    Addicted Member
    Join Date
    Sep 2000
    Posts
    219
    What is the error you are getting?

  5. #5
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    My money is on the datatypes. Use conversion functions to convert to the proper datatype.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  6. #6
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    By the way, the best way to insert a record is to use an Insert statement instead of .Addnew. It is less prone to errors and forgotten update method calls.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    18
    i can't use insert into because i don't know sql that good. How do i convert date() or time() in a real date or time?

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    18
    is this sql statement correct?
    where login is the cookie ("user") and the others come from a form
    --------
    sqladd="INSERT INTO Threads (title,from,text) VALUES ('" & request("strtitle") & "', '" & login & "', '" & request("strtext") & "')"

  9. #9
    Addicted Member tonyenkiducx's Avatar
    Join Date
    Oct 2000
    Location
    London England
    Posts
    147
    Looks right to me dude

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    18

    same error
    is this because it's an asp 3.0 feature? I'm using PWS and it doesn't support asp3.0
    anyway, i'll attach the form and the asp for you to check
    Attached Files Attached Files

  11. #11
    Addicted Member tonyenkiducx's Avatar
    Join Date
    Oct 2000
    Location
    London England
    Posts
    147
    Ok, this will work, and its how I would do it.

    It may not be the fastest, but it will work.

    Rather than using objects to build up a command all the time, you should look more at the conn object, and use it to execute sql code, rather than using all the SQL in-builts, there a little flaky, and not the easiest to use.

    Also consider sticking your connection string in an include file, then you can use the same "conn" object on every page.



    Tony@Work.
    Attached Files Attached Files

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    18
    what's chr(13)?

  13. #13
    Addicted Member tonyenkiducx's Avatar
    Join Date
    Oct 2000
    Location
    London England
    Posts
    147
    A carriage return, when you print code from strings to the browser, there are no carriage returns. So while the front end looks good, the html code is all on one line. So stick in carriage returns to make your HTML nice and readable.

    Does the code for the insert work?

  14. #14
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Post the error message verbatim.

    You may still need to convert the form data to the appropriate data types. Using an insert statement will not change that.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    18
    it's italian, hope you understand it
    ---------
    Microsoft OLE DB Provider for ODBC Drivers errore "80040e14'

    [Microsoft][Driver ODBC Microsoft Access] Errore di sintassi nell'istruzione INSERT INTO.

    /forum/post.asp, riga 17
    ---------
    errore di sintassi means syntax error

    how do i convert all the values?
    from and user are text and 'text' is memo (long text)

  16. #16
    Member
    Join Date
    Jul 2000
    Location
    Ontario, Canada
    Posts
    61

    Exclamation Umm... Do you have SQL

    It looks to me like you do not have an SQL interpreter and thats why the error is comming up maybe try and install SQL and it will work. Correct if I am wrong that does say syntax error in INSERT INTO right, italian is not my strongest language. And here is converting code:

    To convert the date and time to something the database can interperet is the cdate and ctime functions this is how it looks

    rs("timeorwhatever") = ctime(Time)
    rs("dateplace") = cdate(now)

    and the database can interperet that and you should have no problem with that part
    Last edited by absalom; Apr 9th, 2001 at 08:32 PM.
    ---~^ Absalom ^~---

    There is nobody in the world who knows everything there is no one his/her workforce who knows everything what really makes the person smart is that he/she is not affraid to ask for help.

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    18
    an sql interpreter?
    isn't installed on PWS? Where i can get one?

  18. #18
    Member
    Join Date
    Jul 2000
    Location
    Ontario, Canada
    Posts
    61
    I bought version 7 but you can download 2000 from microsoft and can then get the crack on thecrack.net
    ---~^ Absalom ^~---

    There is nobody in the world who knows everything there is no one his/her workforce who knows everything what really makes the person smart is that he/she is not affraid to ask for help.

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    18
    you mean sql server! But it's used to create stored procedures, isn't it?
    With sql server can i run dinamic stored procedures?
    E.g. "SELECT * FROM tab WHERE price > " & request.form("iprice")
    Can i run it under win98?
    Last edited by Maranza; Apr 11th, 2001 at 07:19 AM.

  20. #20
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    SQL Server is more than 'just' Stored Procedures.

    It holds the data itself as well as provides security for the data.

    As far as stored procedures go, your example is not a stored procedure, it is a SQL statement. A Stored Procedure is a group of SQL statements that is precompiled on the server and thus runs much faster. To do 'dynamic' SQL statements within a S.P., you pass in parameters that are used in the SQL statement(s) Where conditions.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

Posting Permissions

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



Click Here to Expand Forum to Full Width