Results 1 to 5 of 5

Thread: SQL Error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Location
    London, England
    Posts
    213
    I am getting an error with my SQL when someone tries to register some details on my website. I am using ASP with a MySQL Database.
    The Error is as follows:

    INSERT INTO table1 values('Sam's','Place', NULL)

    You have an error in your SQL syntax near 's Place', NULL)' at line 1

    The error is being caused by the apostrophe in sam's.

    How can I resolve this ?

  2. #2
    Addicted Member Skeen's Avatar
    Join Date
    Jul 2000
    Location
    Abingdon, Oxon
    Posts
    138

    Are 'Sam's', 'place' variables?
    If so do this:

    SQL = " INSERT INTO table1(field names should go here) " _
    & " values('" & Sam's & "','" & Place & "', NULL)"
    Set SQL = ConnectionObjectName.Execute("SQL")

    Here you are setting thsql command to a variable calle 'SQL'. You then execute it by associating it witha connection to your database by means of a connection object.

    This is how I do it in vb script and it seems to work a treat!

    Hope this helps,

    Cheers 'n' Beers

    Skeen
    "It wasn't the booze that made me snooze, It was the Gin that did me in!"

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Location
    London, England
    Posts
    213
    Hi Skeen

    The problem is that I don't know when the user will submit a word with an apostophe '. When this is not the case it all works ok.

    However, if a variable called strClub includes an apostrophe (eg strClub = "sam's place") there is an SQL error. Is there any way I can check the value of the variable strClub to see if it contains an apostrophe, remove it and then parse the SQL ?

  4. #4
    Junior Member
    Join Date
    Nov 2000
    Posts
    20

    Arrow Reply

    First store the user inputted value in a string
    Use Instr() function to locate the apostrophe(if any).

    if the apostrophe exists then
    replace the apostrophe with a space
    use the variable in the sql statement
    else
    directly use the variable in the sql statement.


    Happy Programming!!!!


  5. #5
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Or you will have to translate the apostrophe to a different character when writing and back to an apostrophe when reading.

    The '~', '|', '`' characters are all good replacements as they are not common in english only systems. You can then parse for them when reading. It adds another layer to the process but unless your users can police themselves from using apostrophes, you don't have alot of options.

    (users police themselves.. bahahahaha.. I kill me)
    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