Link to home
Start Free TrialLog in
Avatar of chandldj
chandldj

asked on

apostrophe issues when sending text to db

I need to send data in a textarea to a memo field in the db(access 2000). the problem is apostrophes or quotes or single quotes can easily end up in the text. I have tried the following but the apostrophe keeps causing an error. I cannot find a solution for this.

        $squo = "'";
        $dquo = """;
        $notes = stripslashes(ereg_replace("'",$squo,$_POST["other_notes"]));
        $notes = stripslashes(ereg_replace('"',$dquo,$_POST["other_notes"]));
        $str_lines = "Insert into lead_lines(empID, leadID, date_, notes) VALUES(".$_POST["pick_emp"].",".odbc_result($rs_leadid, "callID").",'".$_POST["date_entered"]."','".$notes."')";

the resulting sql statement is:

Insert into lead_lines(empID, leadID, date_, notes) VALUES(1,14,'8/19/2005',' This guy seems like a real easy going dude. Might've been high when he ordered.')

The problem is in the might've, i've also tried to insert it like might\'ve -- doesn't work

Is there a way to make it literally write ' instead of placing a ' ?

Because I ran the query in access with the character code rather than the apostrophe and it worked.

Any help is appreciated
ASKER CERTIFIED SOLUTION
Avatar of pauljk1619
pauljk1619

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pauljk1619
pauljk1619

Are you sure you are going to Access here?  The single quotes around the date might be a problem for access.


Insert into lead_lines(empID, leadID, date_, notes) VALUES(1,14,#8/19/2005#,"This guy seems like a real easy going dude. Might've been high when he ordered.")

paul is right. where u have lon texts input by user or otherwise and u r using dynamic queries like in ur example always place it witha  replace command which shall replace a single apostrophe with two.

Prashant
Avatar of chandldj

ASKER

If i replace the single quote with 2, will that not create 2 separate strings that access will think I am sending too many values than fields specified? Also, with the date, I actually have it sitting in a text field so it is happy to take it with surrounding single quotes.
Actually that worked I changed it to
 $squo = " ' ' ";
 $notes = stripslashes(ereg_replace("'",$squo,$_POST["other_notes"]));

it got inserted

Thanks.
How's I not get any points.  :(
dont loose the spirit paul.....
after all its just knowledge sharing. and moreover it was just a 20 points question.

cheers!!
Prashant
guys i dont have any problem with points being awarded to paul....
thats fine with me.
chandldj you may ask Lunchy to change it.

Prashant

I gave the points to prashant because he was the one who mentioned that I should double up the single quote to get it accepted. Paul told me that I should put pund signs around my date. Sorry guys. No disrespect intended.
That is my second comment, did you read my first?