SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Sep 2000
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    asp/access - Insert " into a database??

    Here's my problem...
    I built a quick cms with asp/access ..it works ..
    I have an html form page that inputs records into the database...

    However in my content field im getting this error
    ---
    Error Type:
    Microsoft JET Database Engine (0x80040E14)
    Syntax error (missing operator) in query expression ''"blabab df": afdssdaasdf 'sadflds')'.
    /press/admin/addRelease.asp, line 34
    ----

    I insert " in the content box, but my db sends back an error -- any ideas on how to fix this?

  2. #2
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,200
    Mentioned
    105 Post(s)
    Tagged
    1 Thread(s)
    Try this before you do the insert....

    fstring = Replace(fString, """", """)

    replace fstring with the variable you are trying to insert....
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style

  3. #3
    SitePoint Addict
    Join Date
    Sep 2000
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ?? That seems to get rid of the quotes for good...
    I want to be able to output the quotes if someone wants to view the content.

    Plus, this happens with all characters... ' etc ...

  4. #4
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dave, I think you have got the quotes the wrong way.

    You can try this:

    Code:
    fString = replace(fString, """, "&_quot;")
    fString = replace(fString, "'", "''")
    Remove the underscore in the &_quot;
    Last edited by Husain; Oct 17, 2001 at 13:10.

  5. #5
    SitePoint Addict
    Join Date
    Sep 2000
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers...that was the trick.

    What is the reasoning behind this?

  6. #6
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad to know it worked!

    The first line replaces the qotation mark with the HTML equivalent so that it can be displayed in an HTML page.

    The second line inserts another single quote to prevent the SQL insert statement from ending abnormally. A single quote means that the string in the SQL statement has ended (when in fact it is a quote that your visitor typed as a part of the message!) Doubling the single quotes tells the Database Engine that there's more to come.

    Simple, isn't it?

  7. #7
    SitePoint Addict
    Join Date
    Sep 2000
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that.

    Now im having a similiar problem...this time I want to insert tags like <br><br> <p></p> into my html form that will then populate the db. But, it's coming back with errors about these tags.

    How to prevent that?

  8. #8
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What errors are you getting?


Bookmarks

Posting Permissions

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