SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've been working on a message board for my company. Many things are going ok, but I've been getting this error when someone enters text in a textbox and uses apostrophes in their text (such as don't won't can't). It works fine without the apostrophes. I checked my php.ini and have magic_quotes_gpc to on and I've tried the addslashes() function, but I still get the error.

    This is the error:

    Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression ''This test doesn\'t' WHERE [ID] = 33'., SQL state 37000 in SQLExecDirect in C:\Inetpub\wwwroot\edit.php on line 36

    Here is my script:
    $joketextedt = addslashes($joketextedt);
    if ("SUBMIT"==$updatejoke){
    $sql = "UPDATE Jokes SET JokeText = '$joketextedt' WHERE [ID] = $editjoke2";
    $editJoke = odbc_do($dbcnx,$sql);


    I'm using a MS-access 2k database with php4. Any sudgestions??
    Joe Eliason
    Just a dog learnin' PHP from cat.

  2. #2
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I will answer my own question. After much research and selling my soul to the devil I have come up with the answer. MS-SQL and Access escape single quotes using a ' (single quote) instead of a \ (back slash). So to do this you have to go into the php.ini file and change magic_quotes_sybase = Off to magic_quotes_sybase = On . This tells php to put a ' to close out a singe quote instead of a \.

    Next (very important) you NEED TO MAKE SURE YOUR SINGLE QUOTES ARE RIGHT NEXT TO YOUR VARIABLE IN YOUR INSERT STATEMENT!! For example:

    This is WRONG!!-
    $sql = "UPDATE Jokes SET JokeText = ' $joketextedt ' WHERE [ID] = $editjoke2";

    This is RIGHT!!

    $sql = "UPDATE Jokes SET JokeText = '$joketextedt' WHERE [ID] = $editjoke2";.

    If you don't do this, it will insert extra spaces in your veriable making it so if you ever have to edit the message it won't output correctly and you will have to make a deal with the devil to get it to work (as I had to)!!

    I spent all day trying to get this to work. Luckly there were a couple BBS's out there that had enough pieces to put this together.

    I sure hope this helps someone else out so they don't run into the same muck that I did.

    RUFF!!
    Joe Eliason
    Just a dog learnin' PHP from cat.


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
  •